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/vnd.ms-word', |
||
| 378 | 'xls' => 'application/vnd.ms-excel', |
||
| 379 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 380 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 381 | 'pdf' => 'application/pdf', |
||
| 382 | 'xml' => 'application/xml', |
||
| 383 | 'swf' => 'application/x-shockwave-flash', |
||
| 384 | 'torrent' => 'application/x-bittorrent', |
||
| 385 | 'jar' => 'application/x-jar', |
||
| 386 | // open office (finfo detect as application/zip) |
||
| 387 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
| 388 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
| 389 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
| 390 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
| 391 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
| 392 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
| 393 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
| 394 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
| 395 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
| 396 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
| 397 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
| 398 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
| 399 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
| 400 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
| 401 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
| 402 | // MS office 2007 (finfo detect as application/zip) |
||
| 403 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
| 404 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
| 405 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
| 406 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
| 407 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
| 408 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
| 409 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
| 410 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
| 411 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
| 412 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
| 413 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
| 414 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
| 415 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
| 416 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
| 417 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
| 418 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
| 419 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
| 420 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
| 421 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
| 422 | // archives |
||
| 423 | 'gz' => 'application/x-gzip', |
||
| 424 | 'tgz' => 'application/x-gzip', |
||
| 425 | 'bz' => 'application/x-bzip2', |
||
| 426 | 'bz2' => 'application/x-bzip2', |
||
| 427 | 'tbz' => 'application/x-bzip2', |
||
| 428 | 'xz' => 'application/x-xz', |
||
| 429 | 'zip' => 'application/zip', |
||
| 430 | 'rar' => 'application/x-rar', |
||
| 431 | 'tar' => 'application/x-tar', |
||
| 432 | '7z' => 'application/x-7z-compressed', |
||
| 433 | // texts |
||
| 434 | 'txt' => 'text/plain', |
||
| 435 | 'php' => 'text/x-php', |
||
| 436 | 'html' => 'text/html', |
||
| 437 | 'htm' => 'text/html', |
||
| 438 | 'js' => 'text/javascript', |
||
| 439 | 'css' => 'text/css', |
||
| 440 | 'rtf' => 'text/rtf', |
||
| 441 | 'rtfd' => 'text/rtfd', |
||
| 442 | 'py' => 'text/x-python', |
||
| 443 | 'java' => 'text/x-java-source', |
||
| 444 | 'rb' => 'text/x-ruby', |
||
| 445 | 'sh' => 'text/x-shellscript', |
||
| 446 | 'pl' => 'text/x-perl', |
||
| 447 | 'xml' => 'text/xml', |
||
| 448 | 'sql' => 'text/x-sql', |
||
| 449 | 'c' => 'text/x-csrc', |
||
| 450 | 'h' => 'text/x-chdr', |
||
| 451 | 'cpp' => 'text/x-c++src', |
||
| 452 | 'hh' => 'text/x-c++hdr', |
||
| 453 | 'log' => 'text/plain', |
||
| 454 | 'csv' => 'text/x-comma-separated-values', |
||
| 455 | 'md' => 'text/x-markdown', |
||
| 456 | 'markdown' => 'text/x-markdown', |
||
| 457 | // images |
||
| 458 | 'bmp' => 'image/x-ms-bmp', |
||
| 459 | 'jpg' => 'image/jpeg', |
||
| 460 | 'jpeg' => 'image/jpeg', |
||
| 461 | 'gif' => 'image/gif', |
||
| 462 | 'png' => 'image/png', |
||
| 463 | 'tif' => 'image/tiff', |
||
| 464 | 'tiff' => 'image/tiff', |
||
| 465 | 'tga' => 'image/x-targa', |
||
| 466 | 'psd' => 'image/vnd.adobe.photoshop', |
||
| 467 | 'ai' => 'image/vnd.adobe.photoshop', |
||
| 468 | 'xbm' => 'image/xbm', |
||
| 469 | 'pxm' => 'image/pxm', |
||
| 470 | //audio |
||
| 471 | 'mp3' => 'audio/mpeg', |
||
| 472 | 'mid' => 'audio/midi', |
||
| 473 | 'ogg' => 'audio/ogg', |
||
| 474 | 'oga' => 'audio/ogg', |
||
| 475 | 'm4a' => 'audio/x-m4a', |
||
| 476 | 'wav' => 'audio/wav', |
||
| 477 | 'wma' => 'audio/x-ms-wma', |
||
| 478 | // video |
||
| 479 | 'avi' => 'video/x-msvideo', |
||
| 480 | 'dv' => 'video/x-dv', |
||
| 481 | 'mp4' => 'video/mp4', |
||
| 482 | 'mpeg' => 'video/mpeg', |
||
| 483 | 'mpg' => 'video/mpeg', |
||
| 484 | 'mov' => 'video/quicktime', |
||
| 485 | 'wm' => 'video/x-ms-wmv', |
||
| 486 | 'flv' => 'video/x-flv', |
||
| 487 | 'mkv' => 'video/x-matroska', |
||
| 488 | 'webm' => 'video/webm', |
||
| 489 | 'ogv' => 'video/ogg', |
||
| 490 | 'ogm' => 'video/ogg' |
||
| 491 | ); |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Directory separator - required by client |
||
| 495 | * |
||
| 496 | * @var string |
||
| 497 | **/ |
||
| 498 | protected $separator = DIRECTORY_SEPARATOR; |
||
| 499 | |||
| 500 | /** |
||
| 501 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
| 502 | * |
||
| 503 | * @var string |
||
| 504 | **/ |
||
| 505 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Mimetypes allowed to display |
||
| 509 | * |
||
| 510 | * @var array |
||
| 511 | **/ |
||
| 512 | protected $onlyMimes = array(); |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Store files moved or overwrited files info |
||
| 516 | * |
||
| 517 | * @var array |
||
| 518 | **/ |
||
| 519 | protected $removed = array(); |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Cache storage |
||
| 523 | * |
||
| 524 | * @var array |
||
| 525 | **/ |
||
| 526 | protected $cache = array(); |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Cache by folders |
||
| 530 | * |
||
| 531 | * @var array |
||
| 532 | **/ |
||
| 533 | protected $dirsCache = array(); |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Cache for subdirsCE() |
||
| 537 | * |
||
| 538 | * @var array |
||
| 539 | */ |
||
| 540 | protected $subdirsCache = array(); |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
| 544 | * |
||
| 545 | * @var array |
||
| 546 | */ |
||
| 547 | protected $sessionCache; |
||
| 548 | |||
| 549 | /*********************************************************************/ |
||
| 550 | /* INITIALIZATION */ |
||
| 551 | /*********************************************************************/ |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Prepare driver before mount volume. |
||
| 555 | * Return true if volume is ready. |
||
| 556 | * |
||
| 557 | * @return bool |
||
| 558 | * @author Dmitry (dio) Levashov |
||
| 559 | **/ |
||
| 560 | protected function init() { |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Configure after successfull mount. |
||
| 566 | * By default set thumbnails path and image manipulation library. |
||
| 567 | * |
||
| 568 | * @return void |
||
| 569 | * @author Dmitry (dio) Levashov |
||
| 570 | **/ |
||
| 571 | protected function configure() { |
||
| 612 | |||
| 613 | |||
| 614 | /*********************************************************************/ |
||
| 615 | /* PUBLIC API */ |
||
| 616 | /*********************************************************************/ |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Return driver id. Used as a part of volume id. |
||
| 620 | * |
||
| 621 | * @return string |
||
| 622 | * @author Dmitry (dio) Levashov |
||
| 623 | **/ |
||
| 624 | public function driverId() { |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Return volume id |
||
| 630 | * |
||
| 631 | * @return string |
||
| 632 | * @author Dmitry (dio) Levashov |
||
| 633 | **/ |
||
| 634 | public function id() { |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Return debug info for client |
||
| 640 | * |
||
| 641 | * @return array |
||
| 642 | * @author Dmitry (dio) Levashov |
||
| 643 | **/ |
||
| 644 | public function debug() { |
||
| 652 | |||
| 653 | /** |
||
| 654 | * chmod a file or folder |
||
| 655 | * |
||
| 656 | * @param string $hash file or folder hash to chmod |
||
| 657 | * @param string $mode octal string representing new permissions |
||
| 658 | * @return array|false |
||
| 659 | * @author David Bartle |
||
| 660 | **/ |
||
| 661 | public function chmod($hash, $mode) { |
||
| 697 | |||
| 698 | /** |
||
| 699 | * "Mount" volume. |
||
| 700 | * Return true if volume available for read or write, |
||
| 701 | * false - otherwise |
||
| 702 | * |
||
| 703 | * @return bool |
||
| 704 | * @author Dmitry (dio) Levashov |
||
| 705 | * @author Alexey Sukhotin |
||
| 706 | **/ |
||
| 707 | public function mount(array $opts) { |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Some "unmount" stuffs - may be required by virtual fs |
||
| 973 | * |
||
| 974 | * @return void |
||
| 975 | * @author Dmitry (dio) Levashov |
||
| 976 | **/ |
||
| 977 | public function umount() { |
||
| 979 | |||
| 980 | /** |
||
| 981 | * Return error message from last failed action |
||
| 982 | * |
||
| 983 | * @return array |
||
| 984 | * @author Dmitry (dio) Levashov |
||
| 985 | **/ |
||
| 986 | public function error() { |
||
| 989 | |||
| 990 | /** |
||
| 991 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
| 992 | * |
||
| 993 | * @return array |
||
| 994 | * @author Naoki Sawada |
||
| 995 | */ |
||
| 996 | public function getMimeTable() { |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Set mimetypes allowed to display to client |
||
| 1002 | * |
||
| 1003 | * @param array $mimes |
||
| 1004 | * @return void |
||
| 1005 | * @author Dmitry (dio) Levashov |
||
| 1006 | **/ |
||
| 1007 | public function setMimesFilter($mimes) { |
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Return root folder hash |
||
| 1015 | * |
||
| 1016 | * @return string |
||
| 1017 | * @author Dmitry (dio) Levashov |
||
| 1018 | **/ |
||
| 1019 | public function root() { |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Return target path hash |
||
| 1025 | * |
||
| 1026 | * @param string $path |
||
| 1027 | * @param string $name |
||
| 1028 | * @author Naoki Sawada |
||
| 1029 | */ |
||
| 1030 | public function getHash($path, $name = '') { |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Return root or startPath hash |
||
| 1039 | * |
||
| 1040 | * @return string |
||
| 1041 | * @author Dmitry (dio) Levashov |
||
| 1042 | **/ |
||
| 1043 | public function defaultPath() { |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Return volume options required by client: |
||
| 1049 | * |
||
| 1050 | * @return array |
||
| 1051 | * @author Dmitry (dio) Levashov |
||
| 1052 | **/ |
||
| 1053 | public function options($hash) { |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Get option value of this volume |
||
| 1082 | * |
||
| 1083 | * @param string $name target option name |
||
| 1084 | * @return NULL|mixed target option value |
||
| 1085 | * @author Naoki Sawada |
||
| 1086 | */ |
||
| 1087 | public function getOption($name) { |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Get plugin values of this options |
||
| 1093 | * |
||
| 1094 | * @param string $name Plugin name |
||
| 1095 | * @return NULL|array Plugin values |
||
| 1096 | * @author Naoki Sawada |
||
| 1097 | */ |
||
| 1098 | public function getOptionsPlugin($name = '') { |
||
| 1105 | |||
| 1106 | /** |
||
| 1107 | * Return true if command disabled in options |
||
| 1108 | * |
||
| 1109 | * @param string $cmd command name |
||
| 1110 | * @return bool |
||
| 1111 | * @author Dmitry (dio) Levashov |
||
| 1112 | **/ |
||
| 1113 | public function commandDisabled($cmd) { |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Return true if mime is required mimes list |
||
| 1119 | * |
||
| 1120 | * @param string $mime mime type to check |
||
| 1121 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1122 | * @param bool|null $empty what to return on empty list |
||
| 1123 | * @return bool|null |
||
| 1124 | * @author Dmitry (dio) Levashov |
||
| 1125 | * @author Troex Nevelin |
||
| 1126 | **/ |
||
| 1127 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Return true if voume is readable. |
||
| 1141 | * |
||
| 1142 | * @return bool |
||
| 1143 | * @author Dmitry (dio) Levashov |
||
| 1144 | **/ |
||
| 1145 | public function isReadable() { |
||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Return true if copy from this volume allowed |
||
| 1152 | * |
||
| 1153 | * @return bool |
||
| 1154 | * @author Dmitry (dio) Levashov |
||
| 1155 | **/ |
||
| 1156 | public function copyFromAllowed() { |
||
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Return file path related to root with convert encoging |
||
| 1162 | * |
||
| 1163 | * @param string $hash file hash |
||
| 1164 | * @return string |
||
| 1165 | * @author Dmitry (dio) Levashov |
||
| 1166 | **/ |
||
| 1167 | public function path($hash) { |
||
| 1170 | |||
| 1171 | /** |
||
| 1172 | * Return file real path if file exists |
||
| 1173 | * |
||
| 1174 | * @param string $hash file hash |
||
| 1175 | * @return string |
||
| 1176 | * @author Dmitry (dio) Levashov |
||
| 1177 | **/ |
||
| 1178 | public function realpath($hash) { |
||
| 1182 | |||
| 1183 | /** |
||
| 1184 | * Return list of moved/overwrited files |
||
| 1185 | * |
||
| 1186 | * @return array |
||
| 1187 | * @author Dmitry (dio) Levashov |
||
| 1188 | **/ |
||
| 1189 | public function removed() { |
||
| 1192 | |||
| 1193 | /** |
||
| 1194 | * Clean removed files list |
||
| 1195 | * |
||
| 1196 | * @return void |
||
| 1197 | * @author Dmitry (dio) Levashov |
||
| 1198 | **/ |
||
| 1199 | public function resetRemoved() { |
||
| 1202 | |||
| 1203 | /** |
||
| 1204 | * Return file/dir hash or first founded child hash with required attr == $val |
||
| 1205 | * |
||
| 1206 | * @param string $hash file hash |
||
| 1207 | * @param string $attr attribute name |
||
| 1208 | * @param bool $val attribute value |
||
| 1209 | * @return string|false |
||
| 1210 | * @author Dmitry (dio) Levashov |
||
| 1211 | **/ |
||
| 1212 | public function closest($hash, $attr, $val) { |
||
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Return file info or false on error |
||
| 1218 | * |
||
| 1219 | * @param string $hash file hash |
||
| 1220 | * @param bool $realpath add realpath field to file info |
||
| 1221 | * @return array|false |
||
| 1222 | * @author Dmitry (dio) Levashov |
||
| 1223 | **/ |
||
| 1224 | public function file($hash) { |
||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * Return folder info |
||
| 1239 | * |
||
| 1240 | * @param string $hash folder hash |
||
| 1241 | * @param bool $hidden return hidden file info |
||
| 1242 | * @return array|false |
||
| 1243 | * @author Dmitry (dio) Levashov |
||
| 1244 | **/ |
||
| 1245 | public function dir($hash, $resolveLink=false) { |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Return directory content or false on error |
||
| 1261 | * |
||
| 1262 | * @param string $hash file hash |
||
| 1263 | * @return array|false |
||
| 1264 | * @author Dmitry (dio) Levashov |
||
| 1265 | **/ |
||
| 1266 | public function scandir($hash) { |
||
| 1275 | |||
| 1276 | /** |
||
| 1277 | * Return dir files names list |
||
| 1278 | * |
||
| 1279 | * @param string $hash file hash |
||
| 1280 | * @return array |
||
| 1281 | * @author Dmitry (dio) Levashov |
||
| 1282 | **/ |
||
| 1283 | public function ls($hash) { |
||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * Return subfolders for required folder or false on error |
||
| 1302 | * |
||
| 1303 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1304 | * @param int $deep subdir deep |
||
| 1305 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1306 | * @return array|false |
||
| 1307 | * @author Dmitry (dio) Levashov |
||
| 1308 | **/ |
||
| 1309 | public function tree($hash='', $deep=0, $exclude='') { |
||
| 1320 | |||
| 1321 | /** |
||
| 1322 | * Return part of dirs tree from required dir up to root dir |
||
| 1323 | * |
||
| 1324 | * @param string $hash directory hash |
||
| 1325 | * @param bool|null $lineal only lineal parents |
||
| 1326 | * @return array |
||
| 1327 | * @author Dmitry (dio) Levashov |
||
| 1328 | **/ |
||
| 1329 | public function parents($hash, $lineal = false) { |
||
| 1356 | |||
| 1357 | /** |
||
| 1358 | * Create thumbnail for required file and return its name of false on failed |
||
| 1359 | * |
||
| 1360 | * @return string|false |
||
| 1361 | * @author Dmitry (dio) Levashov |
||
| 1362 | **/ |
||
| 1363 | public function tmb($hash) { |
||
| 1372 | |||
| 1373 | /** |
||
| 1374 | * Return file size / total directory size |
||
| 1375 | * |
||
| 1376 | * @param string file hash |
||
| 1377 | * @return int |
||
| 1378 | * @author Dmitry (dio) Levashov |
||
| 1379 | **/ |
||
| 1380 | public function size($hash) { |
||
| 1383 | |||
| 1384 | /** |
||
| 1385 | * Open file for reading and return file pointer |
||
| 1386 | * |
||
| 1387 | * @param string file hash |
||
| 1388 | * @return Resource |
||
| 1389 | * @author Dmitry (dio) Levashov |
||
| 1390 | **/ |
||
| 1391 | public function open($hash) { |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Close file pointer |
||
| 1402 | * |
||
| 1403 | * @param Resource $fp file pointer |
||
| 1404 | * @param string $hash file hash |
||
| 1405 | * @return void |
||
| 1406 | * @author Dmitry (dio) Levashov |
||
| 1407 | **/ |
||
| 1408 | public function close($fp, $hash) { |
||
| 1411 | |||
| 1412 | /** |
||
| 1413 | * Create directory and return dir info |
||
| 1414 | * |
||
| 1415 | * @param string $dsthash destination directory hash |
||
| 1416 | * @param string $name directory name |
||
| 1417 | * @return array|false |
||
| 1418 | * @author Dmitry (dio) Levashov |
||
| 1419 | **/ |
||
| 1420 | public function mkdir($dsthash, $name) { |
||
| 1447 | |||
| 1448 | /** |
||
| 1449 | * Create empty file and return its info |
||
| 1450 | * |
||
| 1451 | * @param string $dst destination directory |
||
| 1452 | * @param string $name file name |
||
| 1453 | * @return array|false |
||
| 1454 | * @author Dmitry (dio) Levashov |
||
| 1455 | **/ |
||
| 1456 | public function mkfile($dst, $name) { |
||
| 1482 | |||
| 1483 | /** |
||
| 1484 | * Rename file and return file info |
||
| 1485 | * |
||
| 1486 | * @param string $hash file hash |
||
| 1487 | * @param string $name new file name |
||
| 1488 | * @return array|false |
||
| 1489 | * @author Dmitry (dio) Levashov |
||
| 1490 | **/ |
||
| 1491 | public function rename($hash, $name) { |
||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * Create file copy with suffix "copy number" and return its info |
||
| 1540 | * |
||
| 1541 | * @param string $hash file hash |
||
| 1542 | * @param string $suffix suffix to add to file name |
||
| 1543 | * @return array|false |
||
| 1544 | * @author Dmitry (dio) Levashov |
||
| 1545 | **/ |
||
| 1546 | public function duplicate($hash, $suffix='copy') { |
||
| 1567 | |||
| 1568 | /** |
||
| 1569 | * Save uploaded file. |
||
| 1570 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
| 1571 | * |
||
| 1572 | * @param Resource $fp file pointer |
||
| 1573 | * @param string $dst destination folder hash |
||
| 1574 | * @param string $src file name |
||
| 1575 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 1576 | * @return array|false |
||
| 1577 | * @author Dmitry (dio) Levashov |
||
| 1578 | **/ |
||
| 1579 | public function upload($fp, $dst, $name, $tmpname) { |
||
| 1655 | |||
| 1656 | /** |
||
| 1657 | * Paste files |
||
| 1658 | * |
||
| 1659 | * @param Object $volume source volume |
||
| 1660 | * @param string $source file hash |
||
| 1661 | * @param string $dst destination dir hash |
||
| 1662 | * @param bool $rmSrc remove source after copy? |
||
| 1663 | * @return array|false |
||
| 1664 | * @author Dmitry (dio) Levashov |
||
| 1665 | **/ |
||
| 1666 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
| 1754 | |||
| 1755 | /** |
||
| 1756 | * Return file contents |
||
| 1757 | * |
||
| 1758 | * @param string $hash file hash |
||
| 1759 | * @return string|false |
||
| 1760 | * @author Dmitry (dio) Levashov |
||
| 1761 | **/ |
||
| 1762 | public function getContents($hash) { |
||
| 1779 | |||
| 1780 | /** |
||
| 1781 | * Put content in text file and return file info. |
||
| 1782 | * |
||
| 1783 | * @param string $hash file hash |
||
| 1784 | * @param string $content new file content |
||
| 1785 | * @return array |
||
| 1786 | * @author Dmitry (dio) Levashov |
||
| 1787 | **/ |
||
| 1788 | public function putContents($hash, $content) { |
||
| 1823 | |||
| 1824 | /** |
||
| 1825 | * Extract files from archive |
||
| 1826 | * |
||
| 1827 | * @param string $hash archive hash |
||
| 1828 | * @return array|bool |
||
| 1829 | * @author Dmitry (dio) Levashov, |
||
| 1830 | * @author Alexey Sukhotin |
||
| 1831 | **/ |
||
| 1832 | public function extract($hash, $makedir = null) { |
||
| 1871 | |||
| 1872 | /** |
||
| 1873 | * Add files to archive |
||
| 1874 | * |
||
| 1875 | * @return void |
||
| 1876 | **/ |
||
| 1877 | public function archive($hashes, $mime, $name = '') { |
||
| 1921 | |||
| 1922 | /** |
||
| 1923 | * Resize image |
||
| 1924 | * |
||
| 1925 | * @param string $hash image file |
||
| 1926 | * @param int $width new width |
||
| 1927 | * @param int $height new height |
||
| 1928 | * @param int $x X start poistion for crop |
||
| 1929 | * @param int $y Y start poistion for crop |
||
| 1930 | * @param string $mode action how to mainpulate image |
||
| 1931 | * @return array|false |
||
| 1932 | * @author Dmitry (dio) Levashov |
||
| 1933 | * @author Alexey Sukhotin |
||
| 1934 | * @author nao-pon |
||
| 1935 | * @author Troex Nevelin |
||
| 1936 | **/ |
||
| 1937 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0) { |
||
| 2024 | |||
| 2025 | /** |
||
| 2026 | * Remove file/dir |
||
| 2027 | * |
||
| 2028 | * @param string $hash file hash |
||
| 2029 | * @return bool |
||
| 2030 | * @author Dmitry (dio) Levashov |
||
| 2031 | **/ |
||
| 2032 | public function rm($hash) { |
||
| 2037 | |||
| 2038 | /** |
||
| 2039 | * Search files |
||
| 2040 | * |
||
| 2041 | * @param string $q search string |
||
| 2042 | * @param array $mimes |
||
| 2043 | * @return array |
||
| 2044 | * @author Dmitry (dio) Levashov |
||
| 2045 | **/ |
||
| 2046 | public function search($q, $mimes, $hash = null) { |
||
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Return image dimensions |
||
| 2068 | * |
||
| 2069 | * @param string $hash file hash |
||
| 2070 | * @return array |
||
| 2071 | * @author Dmitry (dio) Levashov |
||
| 2072 | **/ |
||
| 2073 | public function dimensions($hash) { |
||
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Return content URL (for netmout volume driver) |
||
| 2083 | * If file.url == 1 requests from JavaScript client with XHR |
||
| 2084 | * |
||
| 2085 | * @param string $hash file hash |
||
| 2086 | * @param array $options options array |
||
| 2087 | * @return boolean|string |
||
| 2088 | * @author Naoki Sawada |
||
| 2089 | */ |
||
| 2090 | public function getContentUrl($hash, $options = array()) { |
||
| 2096 | |||
| 2097 | /** |
||
| 2098 | * Return temp path |
||
| 2099 | * |
||
| 2100 | * @return string |
||
| 2101 | * @author Naoki Sawada |
||
| 2102 | */ |
||
| 2103 | public function getTempPath() { |
||
| 2116 | |||
| 2117 | /** |
||
| 2118 | * (Make &) Get upload taget dirctory hash |
||
| 2119 | * |
||
| 2120 | * @param string $baseTargetHash |
||
| 2121 | * @param string $path |
||
| 2122 | * @param array $result |
||
| 2123 | * @return boolean|string |
||
| 2124 | * @author Naoki Sawada |
||
| 2125 | */ |
||
| 2126 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
| 2153 | |||
| 2154 | /** |
||
| 2155 | * Return this uploadMaxSize value |
||
| 2156 | * |
||
| 2157 | * @return integer |
||
| 2158 | * @author Naoki Sawada |
||
| 2159 | */ |
||
| 2160 | public function getUploadMaxSize() { |
||
| 2163 | |||
| 2164 | /** |
||
| 2165 | * Save error message |
||
| 2166 | * |
||
| 2167 | * @param array error |
||
| 2168 | * @return false |
||
| 2169 | * @author Dmitry(dio) Levashov |
||
| 2170 | **/ |
||
| 2171 | protected function setError($error) { |
||
| 2186 | |||
| 2187 | /*********************************************************************/ |
||
| 2188 | /* FS API */ |
||
| 2189 | /*********************************************************************/ |
||
| 2190 | |||
| 2191 | /***************** server encoding support *******************/ |
||
| 2192 | |||
| 2193 | /** |
||
| 2194 | * Return parent directory path (with convert encording) |
||
| 2195 | * |
||
| 2196 | * @param string $path file path |
||
| 2197 | * @return string |
||
| 2198 | * @author Naoki Sawada |
||
| 2199 | **/ |
||
| 2200 | protected function dirnameCE($path) { |
||
| 2203 | |||
| 2204 | /** |
||
| 2205 | * Return file name (with convert encording) |
||
| 2206 | * |
||
| 2207 | * @param string $path file path |
||
| 2208 | * @return string |
||
| 2209 | * @author Naoki Sawada |
||
| 2210 | **/ |
||
| 2211 | protected function basenameCE($path) { |
||
| 2214 | |||
| 2215 | /** |
||
| 2216 | * Join dir name and file name and return full path. (with convert encording) |
||
| 2217 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 2218 | * |
||
| 2219 | * @param string $dir dir path |
||
| 2220 | * @param string $name file name |
||
| 2221 | * @return string |
||
| 2222 | * @author Naoki Sawada |
||
| 2223 | **/ |
||
| 2224 | protected function joinPathCE($dir, $name) { |
||
| 2227 | |||
| 2228 | /** |
||
| 2229 | * Return normalized path (with convert encording) |
||
| 2230 | * |
||
| 2231 | * @param string $path file path |
||
| 2232 | * @return string |
||
| 2233 | * @author Naoki Sawada |
||
| 2234 | **/ |
||
| 2235 | protected function normpathCE($path) { |
||
| 2238 | |||
| 2239 | /** |
||
| 2240 | * Return file path related to root dir (with convert encording) |
||
| 2241 | * |
||
| 2242 | * @param string $path file path |
||
| 2243 | * @return string |
||
| 2244 | * @author Naoki Sawada |
||
| 2245 | **/ |
||
| 2246 | protected function relpathCE($path) { |
||
| 2249 | |||
| 2250 | /** |
||
| 2251 | * Convert path related to root dir into real path (with convert encording) |
||
| 2252 | * |
||
| 2253 | * @param string $path rel file path |
||
| 2254 | * @return string |
||
| 2255 | * @author Naoki Sawada |
||
| 2256 | **/ |
||
| 2257 | protected function abspathCE($path) { |
||
| 2260 | |||
| 2261 | /** |
||
| 2262 | * Return true if $path is children of $parent (with convert encording) |
||
| 2263 | * |
||
| 2264 | * @param string $path path to check |
||
| 2265 | * @param string $parent parent path |
||
| 2266 | * @return bool |
||
| 2267 | * @author Naoki Sawada |
||
| 2268 | **/ |
||
| 2269 | protected function inpathCE($path, $parent) { |
||
| 2272 | |||
| 2273 | /** |
||
| 2274 | * Open file and return file pointer (with convert encording) |
||
| 2275 | * |
||
| 2276 | * @param string $path file path |
||
| 2277 | * @param bool $write open file for writing |
||
| 2278 | * @return resource|false |
||
| 2279 | * @author Naoki Sawada |
||
| 2280 | **/ |
||
| 2281 | protected function fopenCE($path, $mode='rb') { |
||
| 2284 | |||
| 2285 | /** |
||
| 2286 | * Close opened file (with convert encording) |
||
| 2287 | * |
||
| 2288 | * @param resource $fp file pointer |
||
| 2289 | * @param string $path file path |
||
| 2290 | * @return bool |
||
| 2291 | * @author Naoki Sawada |
||
| 2292 | **/ |
||
| 2293 | protected function fcloseCE($fp, $path='') { |
||
| 2296 | |||
| 2297 | /** |
||
| 2298 | * Create new file and write into it from file pointer. (with convert encording) |
||
| 2299 | * Return new file path or false on error. |
||
| 2300 | * |
||
| 2301 | * @param resource $fp file pointer |
||
| 2302 | * @param string $dir target dir path |
||
| 2303 | * @param string $name file name |
||
| 2304 | * @param array $stat file stat (required by some virtual fs) |
||
| 2305 | * @return bool|string |
||
| 2306 | * @author Naoki Sawada |
||
| 2307 | **/ |
||
| 2308 | protected function saveCE($fp, $dir, $name, $stat) { |
||
| 2311 | |||
| 2312 | /** |
||
| 2313 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
| 2314 | * |
||
| 2315 | * @param string $path dir path |
||
| 2316 | * @return bool |
||
| 2317 | * @author Naoki Sawada |
||
| 2318 | **/ |
||
| 2319 | protected function subdirsCE($path) { |
||
| 2325 | |||
| 2326 | /** |
||
| 2327 | * Return files list in directory (with convert encording) |
||
| 2328 | * |
||
| 2329 | * @param string $path dir path |
||
| 2330 | * @return array |
||
| 2331 | * @author Naoki Sawada |
||
| 2332 | **/ |
||
| 2333 | protected function scandirCE($path) { |
||
| 2336 | |||
| 2337 | /** |
||
| 2338 | * Create symlink (with convert encording) |
||
| 2339 | * |
||
| 2340 | * @param string $source file to link to |
||
| 2341 | * @param string $targetDir folder to create link in |
||
| 2342 | * @param string $name symlink name |
||
| 2343 | * @return bool |
||
| 2344 | * @author Naoki Sawada |
||
| 2345 | **/ |
||
| 2346 | protected function symlinkCE($source, $targetDir, $name) { |
||
| 2349 | |||
| 2350 | /***************** paths *******************/ |
||
| 2351 | |||
| 2352 | /** |
||
| 2353 | * Encode path into hash |
||
| 2354 | * |
||
| 2355 | * @param string file path |
||
| 2356 | * @return string |
||
| 2357 | * @author Dmitry (dio) Levashov |
||
| 2358 | * @author Troex Nevelin |
||
| 2359 | **/ |
||
| 2360 | protected function encode($path) { |
||
| 2381 | |||
| 2382 | /** |
||
| 2383 | * Decode path from hash |
||
| 2384 | * |
||
| 2385 | * @param string file hash |
||
| 2386 | * @return string |
||
| 2387 | * @author Dmitry (dio) Levashov |
||
| 2388 | * @author Troex Nevelin |
||
| 2389 | **/ |
||
| 2390 | protected function decode($hash) { |
||
| 2402 | |||
| 2403 | /** |
||
| 2404 | * Return crypted path |
||
| 2405 | * Not implemented |
||
| 2406 | * |
||
| 2407 | * @param string path |
||
| 2408 | * @return mixed |
||
| 2409 | * @author Dmitry (dio) Levashov |
||
| 2410 | **/ |
||
| 2411 | protected function crypt($path) { |
||
| 2414 | |||
| 2415 | /** |
||
| 2416 | * Return uncrypted path |
||
| 2417 | * Not implemented |
||
| 2418 | * |
||
| 2419 | * @param mixed hash |
||
| 2420 | * @return mixed |
||
| 2421 | * @author Dmitry (dio) Levashov |
||
| 2422 | **/ |
||
| 2423 | protected function uncrypt($hash) { |
||
| 2426 | |||
| 2427 | /** |
||
| 2428 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
| 2429 | * |
||
| 2430 | * @param string $name file name |
||
| 2431 | * @return bool |
||
| 2432 | * @author Dmitry (dio) Levashov |
||
| 2433 | **/ |
||
| 2434 | protected function nameAccepted($name) { |
||
| 2446 | |||
| 2447 | /** |
||
| 2448 | * Return new unique name based on file name and suffix |
||
| 2449 | * |
||
| 2450 | * @param string $path file path |
||
| 2451 | * @param string $suffix suffix append to name |
||
| 2452 | * @return string |
||
| 2453 | * @author Dmitry (dio) Levashov |
||
| 2454 | **/ |
||
| 2455 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { |
||
| 2483 | |||
| 2484 | /** |
||
| 2485 | * Converts character encoding from UTF-8 to server's one |
||
| 2486 | * |
||
| 2487 | * @param mixed $var target string or array var |
||
| 2488 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 2489 | * @param string $unknown replaces character for unknown |
||
| 2490 | * @return mixed |
||
| 2491 | * @author Naoki Sawada |
||
| 2492 | */ |
||
| 2493 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
| 2496 | |||
| 2497 | /** |
||
| 2498 | * Converts character encoding from server's one to UTF-8 |
||
| 2499 | * |
||
| 2500 | * @param mixed $var target string or array var |
||
| 2501 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 2502 | * @param string $unknown replaces character for unknown |
||
| 2503 | * @return mixed |
||
| 2504 | * @author Naoki Sawada |
||
| 2505 | */ |
||
| 2506 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
| 2509 | |||
| 2510 | /** |
||
| 2511 | * Converts character encoding (base function) |
||
| 2512 | * |
||
| 2513 | * @param mixed $var target string or array var |
||
| 2514 | * @param string $from from character encoding |
||
| 2515 | * @param string $to to character encoding |
||
| 2516 | * @param string $locale local locale |
||
| 2517 | * @param string $unknown replaces character for unknown |
||
| 2518 | * @return mixed |
||
| 2519 | */ |
||
| 2520 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
| 2549 | |||
| 2550 | /*********************** util mainly for inheritance class *********************/ |
||
| 2551 | |||
| 2552 | /** |
||
| 2553 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 2554 | * When needing the unique file to a path, give $path to parameter. |
||
| 2555 | * |
||
| 2556 | * @param string $path for get unique file to a path |
||
| 2557 | * @return string|false |
||
| 2558 | * @author Naoki Sawada |
||
| 2559 | */ |
||
| 2560 | protected function getTempFile($path = '') { |
||
| 2586 | |||
| 2587 | /** |
||
| 2588 | * File path of local server side work file path |
||
| 2589 | * |
||
| 2590 | * @param string $path path need convert encoding to server encoding |
||
| 2591 | * @return string |
||
| 2592 | * @author Naoki Sawada |
||
| 2593 | */ |
||
| 2594 | protected function getWorkFile($path) { |
||
| 2609 | |||
| 2610 | /** |
||
| 2611 | * Get image size array with `dimensions` |
||
| 2612 | * |
||
| 2613 | * @param string $path path need convert encoding to server encoding |
||
| 2614 | * @param string $mime file mime type |
||
| 2615 | * @return array|false |
||
| 2616 | */ |
||
| 2617 | public function getImageSize($path, $mime = '') { |
||
| 2629 | |||
| 2630 | /** |
||
| 2631 | * Delete dirctory trees |
||
| 2632 | * |
||
| 2633 | * @param string $localpath path need convert encoding to server encoding |
||
| 2634 | * @return boolean |
||
| 2635 | * @author Naoki Sawada |
||
| 2636 | */ |
||
| 2637 | protected function delTree($localpath) { |
||
| 2646 | |||
| 2647 | /*********************** file stat *********************/ |
||
| 2648 | |||
| 2649 | /** |
||
| 2650 | * Check file attribute |
||
| 2651 | * |
||
| 2652 | * @param string $path file path |
||
| 2653 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 2654 | * @param bool $val attribute value returned by file system |
||
| 2655 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 2656 | * @return bool |
||
| 2657 | * @author Dmitry (dio) Levashov |
||
| 2658 | **/ |
||
| 2659 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
| 2693 | |||
| 2694 | /** |
||
| 2695 | * Return true if file with given name can be created in given folder. |
||
| 2696 | * |
||
| 2697 | * @param string $dir parent dir path |
||
| 2698 | * @param string $name new file name |
||
| 2699 | * @return bool |
||
| 2700 | * @author Dmitry (dio) Levashov |
||
| 2701 | **/ |
||
| 2702 | protected function allowCreate($dir, $name, $isDir = null) { |
||
| 2725 | |||
| 2726 | /** |
||
| 2727 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 2728 | * |
||
| 2729 | * @param string $mime |
||
| 2730 | * @return boolean |
||
| 2731 | */ |
||
| 2732 | protected function allowPutMime($mime) { |
||
| 2750 | |||
| 2751 | /** |
||
| 2752 | * Return fileinfo |
||
| 2753 | * |
||
| 2754 | * @param string $path file cache |
||
| 2755 | * @return array |
||
| 2756 | * @author Dmitry (dio) Levashov |
||
| 2757 | **/ |
||
| 2758 | protected function stat($path) { |
||
| 2783 | |||
| 2784 | /** |
||
| 2785 | * Put file stat in cache and return it |
||
| 2786 | * |
||
| 2787 | * @param string $path file path |
||
| 2788 | * @param array $stat file stat |
||
| 2789 | * @return array |
||
| 2790 | * @author Dmitry (dio) Levashov |
||
| 2791 | **/ |
||
| 2792 | protected function updateCache($path, $stat) { |
||
| 2931 | |||
| 2932 | /** |
||
| 2933 | * Get stat for folder content and put in cache |
||
| 2934 | * |
||
| 2935 | * @param string $path |
||
| 2936 | * @return void |
||
| 2937 | * @author Dmitry (dio) Levashov |
||
| 2938 | **/ |
||
| 2939 | protected function cacheDir($path) { |
||
| 2952 | |||
| 2953 | /** |
||
| 2954 | * Clean cache |
||
| 2955 | * |
||
| 2956 | * @return void |
||
| 2957 | * @author Dmitry (dio) Levashov |
||
| 2958 | **/ |
||
| 2959 | protected function clearcache() { |
||
| 2962 | |||
| 2963 | /** |
||
| 2964 | * Return file mimetype |
||
| 2965 | * |
||
| 2966 | * @param string $path file path |
||
| 2967 | * @return string |
||
| 2968 | * @author Dmitry (dio) Levashov |
||
| 2969 | **/ |
||
| 2970 | protected function mimetype($path, $name = '') { |
||
| 3015 | |||
| 3016 | /** |
||
| 3017 | * Detect file mimetype using "internal" method |
||
| 3018 | * |
||
| 3019 | * @param string $path file path |
||
| 3020 | * @return string |
||
| 3021 | * @author Dmitry (dio) Levashov |
||
| 3022 | **/ |
||
| 3023 | static protected function mimetypeInternalDetect($path) { |
||
| 3029 | |||
| 3030 | /** |
||
| 3031 | * Return file/total directory size |
||
| 3032 | * |
||
| 3033 | * @param string $path file path |
||
| 3034 | * @return int |
||
| 3035 | * @author Dmitry (dio) Levashov |
||
| 3036 | **/ |
||
| 3037 | protected function countSize($path) { |
||
| 3062 | |||
| 3063 | /** |
||
| 3064 | * Return true if all mimes is directory or files |
||
| 3065 | * |
||
| 3066 | * @param string $mime1 mimetype |
||
| 3067 | * @param string $mime2 mimetype |
||
| 3068 | * @return bool |
||
| 3069 | * @author Dmitry (dio) Levashov |
||
| 3070 | **/ |
||
| 3071 | protected function isSameType($mime1, $mime2) { |
||
| 3074 | |||
| 3075 | /** |
||
| 3076 | * If file has required attr == $val - return file path, |
||
| 3077 | * If dir has child with has required attr == $val - return child path |
||
| 3078 | * |
||
| 3079 | * @param string $path file path |
||
| 3080 | * @param string $attr attribute name |
||
| 3081 | * @param bool $val attribute value |
||
| 3082 | * @return string|false |
||
| 3083 | * @author Dmitry (dio) Levashov |
||
| 3084 | **/ |
||
| 3085 | protected function closestByAttr($path, $attr, $val) { |
||
| 3102 | |||
| 3103 | /** |
||
| 3104 | * Return first found children with required attr == $val |
||
| 3105 | * |
||
| 3106 | * @param string $path file path |
||
| 3107 | * @param string $attr attribute name |
||
| 3108 | * @param bool $val attribute value |
||
| 3109 | * @return string|false |
||
| 3110 | * @author Dmitry (dio) Levashov |
||
| 3111 | **/ |
||
| 3112 | protected function childsByAttr($path, $attr, $val) { |
||
| 3120 | |||
| 3121 | /***************** get content *******************/ |
||
| 3122 | |||
| 3123 | /** |
||
| 3124 | * Return required dir's files info. |
||
| 3125 | * If onlyMimes is set - return only dirs and files of required mimes |
||
| 3126 | * |
||
| 3127 | * @param string $path dir path |
||
| 3128 | * @return array |
||
| 3129 | * @author Dmitry (dio) Levashov |
||
| 3130 | **/ |
||
| 3131 | protected function getScandir($path) { |
||
| 3144 | |||
| 3145 | |||
| 3146 | /** |
||
| 3147 | * Return subdirs tree |
||
| 3148 | * |
||
| 3149 | * @param string $path parent dir path |
||
| 3150 | * @param int $deep tree deep |
||
| 3151 | * @return array |
||
| 3152 | * @author Dmitry (dio) Levashov |
||
| 3153 | **/ |
||
| 3154 | protected function gettree($path, $deep, $exclude='') { |
||
| 3172 | |||
| 3173 | /** |
||
| 3174 | * Recursive files search |
||
| 3175 | * |
||
| 3176 | * @param string $path dir path |
||
| 3177 | * @param string $q search string |
||
| 3178 | * @param array $mimes |
||
| 3179 | * @return array |
||
| 3180 | * @author Dmitry (dio) Levashov |
||
| 3181 | **/ |
||
| 3182 | protected function doSearch($path, $q, $mimes) { |
||
| 3218 | |||
| 3219 | /********************** manuipulations ******************/ |
||
| 3220 | |||
| 3221 | /** |
||
| 3222 | * Copy file/recursive copy dir only in current volume. |
||
| 3223 | * Return new file path or false. |
||
| 3224 | * |
||
| 3225 | * @param string $src source path |
||
| 3226 | * @param string $dst destination dir path |
||
| 3227 | * @param string $name new file name (optionaly) |
||
| 3228 | * @return string|false |
||
| 3229 | * @author Dmitry (dio) Levashov |
||
| 3230 | **/ |
||
| 3231 | protected function copy($src, $dst, $name) { |
||
| 3273 | |||
| 3274 | /** |
||
| 3275 | * Move file |
||
| 3276 | * Return new file path or false. |
||
| 3277 | * |
||
| 3278 | * @param string $src source path |
||
| 3279 | * @param string $dst destination dir path |
||
| 3280 | * @param string $name new file name |
||
| 3281 | * @return string|false |
||
| 3282 | * @author Dmitry (dio) Levashov |
||
| 3283 | **/ |
||
| 3284 | protected function move($src, $dst, $name) { |
||
| 3298 | |||
| 3299 | /** |
||
| 3300 | * Copy file from another volume. |
||
| 3301 | * Return new file path or false. |
||
| 3302 | * |
||
| 3303 | * @param Object $volume source volume |
||
| 3304 | * @param string $src source file hash |
||
| 3305 | * @param string $destination destination dir path |
||
| 3306 | * @param string $name file name |
||
| 3307 | * @return string|false |
||
| 3308 | * @author Dmitry (dio) Levashov |
||
| 3309 | **/ |
||
| 3310 | protected function copyFrom($volume, $src, $destination, $name) { |
||
| 3372 | |||
| 3373 | /** |
||
| 3374 | * Remove file/ recursive remove dir |
||
| 3375 | * |
||
| 3376 | * @param string $path file path |
||
| 3377 | * @param bool $force try to remove even if file locked |
||
| 3378 | * @return bool |
||
| 3379 | * @author Dmitry (dio) Levashov |
||
| 3380 | **/ |
||
| 3381 | protected function remove($path, $force = false) { |
||
| 3411 | |||
| 3412 | |||
| 3413 | /************************* thumbnails **************************/ |
||
| 3414 | |||
| 3415 | /** |
||
| 3416 | * Return thumbnail file name for required file |
||
| 3417 | * |
||
| 3418 | * @param array $stat file stat |
||
| 3419 | * @return string |
||
| 3420 | * @author Dmitry (dio) Levashov |
||
| 3421 | **/ |
||
| 3422 | protected function tmbname($stat) { |
||
| 3425 | |||
| 3426 | /** |
||
| 3427 | * Return thumnbnail name if exists |
||
| 3428 | * |
||
| 3429 | * @param string $path file path |
||
| 3430 | * @param array $stat file stat |
||
| 3431 | * @return string|false |
||
| 3432 | * @author Dmitry (dio) Levashov |
||
| 3433 | **/ |
||
| 3434 | protected function gettmb($path, $stat) { |
||
| 3448 | |||
| 3449 | /** |
||
| 3450 | * Return true if thumnbnail for required file can be created |
||
| 3451 | * |
||
| 3452 | * @param string $path thumnbnail path |
||
| 3453 | * @param array $stat file stat |
||
| 3454 | * @param bool $checkTmbPath |
||
| 3455 | * @return string|bool |
||
| 3456 | * @author Dmitry (dio) Levashov |
||
| 3457 | **/ |
||
| 3458 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
| 3465 | |||
| 3466 | /** |
||
| 3467 | * Return true if required file can be resized. |
||
| 3468 | * By default - the same as canCreateTmb |
||
| 3469 | * |
||
| 3470 | * @param string $path thumnbnail path |
||
| 3471 | * @param array $stat file stat |
||
| 3472 | * @return string|bool |
||
| 3473 | * @author Dmitry (dio) Levashov |
||
| 3474 | **/ |
||
| 3475 | protected function canResize($path, $stat) { |
||
| 3478 | |||
| 3479 | /** |
||
| 3480 | * Create thumnbnail and return it's URL on success |
||
| 3481 | * |
||
| 3482 | * @param string $path file path |
||
| 3483 | * @param string $mime file mime type |
||
| 3484 | * @return string|false |
||
| 3485 | * @author Dmitry (dio) Levashov |
||
| 3486 | **/ |
||
| 3487 | protected function createTmb($path, $stat) { |
||
| 3557 | |||
| 3558 | /** |
||
| 3559 | * Resize image |
||
| 3560 | * |
||
| 3561 | * @param string $path image file |
||
| 3562 | * @param int $width new width |
||
| 3563 | * @param int $height new height |
||
| 3564 | * @param bool $keepProportions crop image |
||
| 3565 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 3566 | * @param string $destformat image destination format |
||
| 3567 | * @return string|false |
||
| 3568 | * @author Dmitry (dio) Levashov |
||
| 3569 | * @author Alexey Sukhotin |
||
| 3570 | **/ |
||
| 3571 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null) { |
||
| 3664 | |||
| 3665 | /** |
||
| 3666 | * Crop image |
||
| 3667 | * |
||
| 3668 | * @param string $path image file |
||
| 3669 | * @param int $width crop width |
||
| 3670 | * @param int $height crop height |
||
| 3671 | * @param bool $x crop left offset |
||
| 3672 | * @param bool $y crop top offset |
||
| 3673 | * @param string $destformat image destination format |
||
| 3674 | * @return string|false |
||
| 3675 | * @author Dmitry (dio) Levashov |
||
| 3676 | * @author Alexey Sukhotin |
||
| 3677 | **/ |
||
| 3678 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null) { |
||
| 3752 | |||
| 3753 | /** |
||
| 3754 | * Put image to square |
||
| 3755 | * |
||
| 3756 | * @param string $path image file |
||
| 3757 | * @param int $width square width |
||
| 3758 | * @param int $height square height |
||
| 3759 | * @param int $align reserved |
||
| 3760 | * @param int $valign reserved |
||
| 3761 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3762 | * @param string $destformat image destination format |
||
| 3763 | * @return string|false |
||
| 3764 | * @author Dmitry (dio) Levashov |
||
| 3765 | * @author Alexey Sukhotin |
||
| 3766 | **/ |
||
| 3767 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null) { |
||
| 3845 | |||
| 3846 | /** |
||
| 3847 | * Rotate image |
||
| 3848 | * |
||
| 3849 | * @param string $path image file |
||
| 3850 | * @param int $degree rotete degrees |
||
| 3851 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3852 | * @param string $destformat image destination format |
||
| 3853 | * @return string|false |
||
| 3854 | * @author nao-pon |
||
| 3855 | * @author Troex Nevelin |
||
| 3856 | **/ |
||
| 3857 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null) { |
||
| 3937 | |||
| 3938 | /** |
||
| 3939 | * Execute shell command |
||
| 3940 | * |
||
| 3941 | * @param string $command command line |
||
| 3942 | * @param array $output stdout strings |
||
| 3943 | * @param array $return_var process exit code |
||
| 3944 | * @param array $error_output stderr strings |
||
| 3945 | * @return int exit code |
||
| 3946 | * @author Alexey Sukhotin |
||
| 3947 | **/ |
||
| 3948 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
| 3978 | |||
| 3979 | /** |
||
| 3980 | * Remove thumbnail, also remove recursively if stat is directory |
||
| 3981 | * |
||
| 3982 | * @param string $stat file stat |
||
| 3983 | * @return void |
||
| 3984 | * @author Dmitry (dio) Levashov |
||
| 3985 | * @author Naoki Sawada |
||
| 3986 | * @author Troex Nevelin |
||
| 3987 | **/ |
||
| 3988 | protected function rmTmb($stat) { |
||
| 4001 | |||
| 4002 | /** |
||
| 4003 | * Create an gd image according to the specified mime type |
||
| 4004 | * |
||
| 4005 | * @param string $path image file |
||
| 4006 | * @param string $mime |
||
| 4007 | * @return gd image resource identifier |
||
| 4008 | */ |
||
| 4009 | protected function gdImageCreate($path,$mime){ |
||
| 4025 | |||
| 4026 | /** |
||
| 4027 | * Output gd image to file |
||
| 4028 | * |
||
| 4029 | * @param resource $image gd image resource |
||
| 4030 | * @param string $filename The path to save the file to. |
||
| 4031 | * @param string $destformat The Image type to use for $filename |
||
| 4032 | * @param string $mime The original image mime type |
||
| 4033 | */ |
||
| 4034 | protected function gdImage($image, $filename, $destformat, $mime ){ |
||
| 4046 | |||
| 4047 | /** |
||
| 4048 | * Assign the proper background to a gd image |
||
| 4049 | * |
||
| 4050 | * @param resource $image gd image resource |
||
| 4051 | * @param string $bgcolor background color in #rrggbb format |
||
| 4052 | */ |
||
| 4053 | protected function gdImageBackground($image, $bgcolor){ |
||
| 4066 | |||
| 4067 | /*********************** misc *************************/ |
||
| 4068 | |||
| 4069 | /** |
||
| 4070 | * Return smart formatted date |
||
| 4071 | * |
||
| 4072 | * @param int $ts file timestamp |
||
| 4073 | * @return string |
||
| 4074 | * @author Dmitry (dio) Levashov |
||
| 4075 | **/ |
||
| 4076 | // protected function formatDate($ts) { |
||
| 4077 | // if ($ts > $this->today) { |
||
| 4078 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 4079 | // } |
||
| 4080 | // |
||
| 4081 | // if ($ts > $this->yesterday) { |
||
| 4082 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 4083 | // } |
||
| 4084 | // |
||
| 4085 | // return date($this->options['dateFormat'], $ts); |
||
| 4086 | // } |
||
| 4087 | |||
| 4088 | /** |
||
| 4089 | * Find position of first occurrence of string in a string with multibyte support |
||
| 4090 | * |
||
| 4091 | * @param string $haystack The string being checked. |
||
| 4092 | * @param string $needle The string to find in haystack. |
||
| 4093 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 4094 | * @return int|bool |
||
| 4095 | * @author Alexey Sukhotin |
||
| 4096 | **/ |
||
| 4097 | protected function stripos($haystack , $needle , $offset = 0) { |
||
| 4105 | |||
| 4106 | /** |
||
| 4107 | * Get server side available archivers |
||
| 4108 | * |
||
| 4109 | * @param bool $use_cache |
||
| 4110 | * @return array |
||
| 4111 | */ |
||
| 4112 | protected function getArchivers($use_cache = true) { |
||
| 4228 | |||
| 4229 | /** |
||
| 4230 | * Resolve relative / (Unix-like)absolute path |
||
| 4231 | * |
||
| 4232 | * @param string $path target path |
||
| 4233 | * @param string $base base path |
||
| 4234 | * @return string |
||
| 4235 | */ |
||
| 4236 | protected function getFullPath($path, $base) { |
||
| 4283 | |||
| 4284 | /** |
||
| 4285 | * Remove directory recursive on local file system |
||
| 4286 | * |
||
| 4287 | * @param string $dir Target dirctory path |
||
| 4288 | * @return boolean |
||
| 4289 | * @author Naoki Sawada |
||
| 4290 | */ |
||
| 4291 | public function rmdirRecursive($dir) { |
||
| 4311 | |||
| 4312 | /** |
||
| 4313 | * Create archive and return its path |
||
| 4314 | * |
||
| 4315 | * @param string $dir target dir |
||
| 4316 | * @param array $files files names list |
||
| 4317 | * @param string $name archive name |
||
| 4318 | * @param array $arc archiver options |
||
| 4319 | * @return string|bool |
||
| 4320 | * @author Dmitry (dio) Levashov, |
||
| 4321 | * @author Alexey Sukhotin |
||
| 4322 | * @author Naoki Sawada |
||
| 4323 | **/ |
||
| 4324 | protected function makeArchive($dir, $files, $name, $arc) { |
||
| 4342 | |||
| 4343 | /** |
||
| 4344 | * Unpack archive |
||
| 4345 | * |
||
| 4346 | * @param string $path archive path |
||
| 4347 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 4348 | * @param bool $remove remove archive ( unlink($path) ) |
||
| 4349 | * @return void |
||
| 4350 | * @author Dmitry (dio) Levashov |
||
| 4351 | * @author Alexey Sukhotin |
||
| 4352 | * @author Naoki Sawada |
||
| 4353 | **/ |
||
| 4354 | protected function unpackArchive($path, $arc, $remove = true) { |
||
| 4369 | |||
| 4370 | /** |
||
| 4371 | * Create Zip archive using PHP class ZipArchive |
||
| 4372 | * |
||
| 4373 | * @param string $dir target dir |
||
| 4374 | * @param array $files files names list |
||
| 4375 | * @param string|object $zipPath Zip archive name |
||
| 4376 | * @return void |
||
| 4377 | * @author Naoki Sawada |
||
| 4378 | */ |
||
| 4379 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
| 4417 | |||
| 4418 | /** |
||
| 4419 | * Unpack Zip archive using PHP class ZipArchive |
||
| 4420 | * |
||
| 4421 | * @param string $zipPath Zip archive name |
||
| 4422 | * @param string $toDir Extract to path |
||
| 4423 | * @return bool |
||
| 4424 | * @author Naoki Sawada |
||
| 4425 | */ |
||
| 4426 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
| 4438 | |||
| 4439 | /**==================================* abstract methods *====================================**/ |
||
| 4440 | |||
| 4441 | /*********************** paths/urls *************************/ |
||
| 4442 | |||
| 4443 | /** |
||
| 4444 | * Return parent directory path |
||
| 4445 | * |
||
| 4446 | * @param string $path file path |
||
| 4447 | * @return string |
||
| 4448 | * @author Dmitry (dio) Levashov |
||
| 4449 | **/ |
||
| 4450 | abstract protected function _dirname($path); |
||
| 4451 | |||
| 4452 | /** |
||
| 4453 | * Return file name |
||
| 4454 | * |
||
| 4455 | * @param string $path file path |
||
| 4456 | * @return string |
||
| 4457 | * @author Dmitry (dio) Levashov |
||
| 4458 | **/ |
||
| 4459 | abstract protected function _basename($path); |
||
| 4460 | |||
| 4461 | /** |
||
| 4462 | * Join dir name and file name and return full path. |
||
| 4463 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 4464 | * |
||
| 4465 | * @param string $dir dir path |
||
| 4466 | * @param string $name file name |
||
| 4467 | * @return string |
||
| 4468 | * @author Dmitry (dio) Levashov |
||
| 4469 | **/ |
||
| 4470 | abstract protected function _joinPath($dir, $name); |
||
| 4471 | |||
| 4472 | /** |
||
| 4473 | * Return normalized path |
||
| 4474 | * |
||
| 4475 | * @param string $path file path |
||
| 4476 | * @return string |
||
| 4477 | * @author Dmitry (dio) Levashov |
||
| 4478 | **/ |
||
| 4479 | abstract protected function _normpath($path); |
||
| 4480 | |||
| 4481 | /** |
||
| 4482 | * Return file path related to root dir |
||
| 4483 | * |
||
| 4484 | * @param string $path file path |
||
| 4485 | * @return string |
||
| 4486 | * @author Dmitry (dio) Levashov |
||
| 4487 | **/ |
||
| 4488 | abstract protected function _relpath($path); |
||
| 4489 | |||
| 4490 | /** |
||
| 4491 | * Convert path related to root dir into real path |
||
| 4492 | * |
||
| 4493 | * @param string $path rel file path |
||
| 4494 | * @return string |
||
| 4495 | * @author Dmitry (dio) Levashov |
||
| 4496 | **/ |
||
| 4497 | abstract protected function _abspath($path); |
||
| 4498 | |||
| 4499 | /** |
||
| 4500 | * Return fake path started from root dir. |
||
| 4501 | * Required to show path on client side. |
||
| 4502 | * |
||
| 4503 | * @param string $path file path |
||
| 4504 | * @return string |
||
| 4505 | * @author Dmitry (dio) Levashov |
||
| 4506 | **/ |
||
| 4507 | abstract protected function _path($path); |
||
| 4508 | |||
| 4509 | /** |
||
| 4510 | * Return true if $path is children of $parent |
||
| 4511 | * |
||
| 4512 | * @param string $path path to check |
||
| 4513 | * @param string $parent parent path |
||
| 4514 | * @return bool |
||
| 4515 | * @author Dmitry (dio) Levashov |
||
| 4516 | **/ |
||
| 4517 | abstract protected function _inpath($path, $parent); |
||
| 4518 | |||
| 4519 | /** |
||
| 4520 | * Return stat for given path. |
||
| 4521 | * Stat contains following fields: |
||
| 4522 | * - (int) size file size in b. required |
||
| 4523 | * - (int) ts file modification time in unix time. required |
||
| 4524 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 4525 | * - (bool) read read permissions. required |
||
| 4526 | * - (bool) write write permissions. required |
||
| 4527 | * - (bool) locked is object locked. optionally |
||
| 4528 | * - (bool) hidden is object hidden. optionally |
||
| 4529 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 4530 | * - (string) target for symlinks - link target path. optionally |
||
| 4531 | * |
||
| 4532 | * If file does not exists - returns empty array or false. |
||
| 4533 | * |
||
| 4534 | * @param string $path file path |
||
| 4535 | * @return array|false |
||
| 4536 | * @author Dmitry (dio) Levashov |
||
| 4537 | **/ |
||
| 4538 | abstract protected function _stat($path); |
||
| 4539 | |||
| 4540 | |||
| 4541 | /***************** file stat ********************/ |
||
| 4542 | |||
| 4543 | |||
| 4544 | /** |
||
| 4545 | * Return true if path is dir and has at least one childs directory |
||
| 4546 | * |
||
| 4547 | * @param string $path dir path |
||
| 4548 | * @return bool |
||
| 4549 | * @author Dmitry (dio) Levashov |
||
| 4550 | **/ |
||
| 4551 | abstract protected function _subdirs($path); |
||
| 4552 | |||
| 4553 | /** |
||
| 4554 | * Return object width and height |
||
| 4555 | * Ususaly used for images, but can be realize for video etc... |
||
| 4556 | * |
||
| 4557 | * @param string $path file path |
||
| 4558 | * @param string $mime file mime type |
||
| 4559 | * @return string |
||
| 4560 | * @author Dmitry (dio) Levashov |
||
| 4561 | **/ |
||
| 4562 | abstract protected function _dimensions($path, $mime); |
||
| 4563 | |||
| 4564 | /******************** file/dir content *********************/ |
||
| 4565 | |||
| 4566 | /** |
||
| 4567 | * Return files list in directory |
||
| 4568 | * |
||
| 4569 | * @param string $path dir path |
||
| 4570 | * @return array |
||
| 4571 | * @author Dmitry (dio) Levashov |
||
| 4572 | **/ |
||
| 4573 | abstract protected function _scandir($path); |
||
| 4574 | |||
| 4575 | /** |
||
| 4576 | * Open file and return file pointer |
||
| 4577 | * |
||
| 4578 | * @param string $path file path |
||
| 4579 | * @param bool $write open file for writing |
||
| 4580 | * @return resource|false |
||
| 4581 | * @author Dmitry (dio) Levashov |
||
| 4582 | **/ |
||
| 4583 | abstract protected function _fopen($path, $mode="rb"); |
||
| 4584 | |||
| 4585 | /** |
||
| 4586 | * Close opened file |
||
| 4587 | * |
||
| 4588 | * @param resource $fp file pointer |
||
| 4589 | * @param string $path file path |
||
| 4590 | * @return bool |
||
| 4591 | * @author Dmitry (dio) Levashov |
||
| 4592 | **/ |
||
| 4593 | abstract protected function _fclose($fp, $path=''); |
||
| 4594 | |||
| 4595 | /******************** file/dir manipulations *************************/ |
||
| 4596 | |||
| 4597 | /** |
||
| 4598 | * Create dir and return created dir path or false on failed |
||
| 4599 | * |
||
| 4600 | * @param string $path parent dir path |
||
| 4601 | * @param string $name new directory name |
||
| 4602 | * @return string|bool |
||
| 4603 | * @author Dmitry (dio) Levashov |
||
| 4604 | **/ |
||
| 4605 | abstract protected function _mkdir($path, $name); |
||
| 4606 | |||
| 4607 | /** |
||
| 4608 | * Create file and return it's path or false on failed |
||
| 4609 | * |
||
| 4610 | * @param string $path parent dir path |
||
| 4611 | * @param string $name new file name |
||
| 4612 | * @return string|bool |
||
| 4613 | * @author Dmitry (dio) Levashov |
||
| 4614 | **/ |
||
| 4615 | abstract protected function _mkfile($path, $name); |
||
| 4616 | |||
| 4617 | /** |
||
| 4618 | * Create symlink |
||
| 4619 | * |
||
| 4620 | * @param string $source file to link to |
||
| 4621 | * @param string $targetDir folder to create link in |
||
| 4622 | * @param string $name symlink name |
||
| 4623 | * @return bool |
||
| 4624 | * @author Dmitry (dio) Levashov |
||
| 4625 | **/ |
||
| 4626 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 4627 | |||
| 4628 | /** |
||
| 4629 | * Copy file into another file (only inside one volume) |
||
| 4630 | * |
||
| 4631 | * @param string $source source file path |
||
| 4632 | * @param string $target target dir path |
||
| 4633 | * @param string $name file name |
||
| 4634 | * @return bool |
||
| 4635 | * @author Dmitry (dio) Levashov |
||
| 4636 | **/ |
||
| 4637 | abstract protected function _copy($source, $targetDir, $name); |
||
| 4638 | |||
| 4639 | /** |
||
| 4640 | * Move file into another parent dir. |
||
| 4641 | * Return new file path or false. |
||
| 4642 | * |
||
| 4643 | * @param string $source source file path |
||
| 4644 | * @param string $target target dir path |
||
| 4645 | * @param string $name file name |
||
| 4646 | * @return string|bool |
||
| 4647 | * @author Dmitry (dio) Levashov |
||
| 4648 | **/ |
||
| 4649 | abstract protected function _move($source, $targetDir, $name); |
||
| 4650 | |||
| 4651 | /** |
||
| 4652 | * Remove file |
||
| 4653 | * |
||
| 4654 | * @param string $path file path |
||
| 4655 | * @return bool |
||
| 4656 | * @author Dmitry (dio) Levashov |
||
| 4657 | **/ |
||
| 4658 | abstract protected function _unlink($path); |
||
| 4659 | |||
| 4660 | /** |
||
| 4661 | * Remove dir |
||
| 4662 | * |
||
| 4663 | * @param string $path dir path |
||
| 4664 | * @return bool |
||
| 4665 | * @author Dmitry (dio) Levashov |
||
| 4666 | **/ |
||
| 4667 | abstract protected function _rmdir($path); |
||
| 4668 | |||
| 4669 | /** |
||
| 4670 | * Create new file and write into it from file pointer. |
||
| 4671 | * Return new file path or false on error. |
||
| 4672 | * |
||
| 4673 | * @param resource $fp file pointer |
||
| 4674 | * @param string $dir target dir path |
||
| 4675 | * @param string $name file name |
||
| 4676 | * @param array $stat file stat (required by some virtual fs) |
||
| 4677 | * @return bool|string |
||
| 4678 | * @author Dmitry (dio) Levashov |
||
| 4679 | **/ |
||
| 4680 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 4681 | |||
| 4682 | /** |
||
| 4683 | * Get file contents |
||
| 4684 | * |
||
| 4685 | * @param string $path file path |
||
| 4686 | * @return string|false |
||
| 4687 | * @author Dmitry (dio) Levashov |
||
| 4688 | **/ |
||
| 4689 | abstract protected function _getContents($path); |
||
| 4690 | |||
| 4691 | /** |
||
| 4692 | * Write a string to a file |
||
| 4693 | * |
||
| 4694 | * @param string $path file path |
||
| 4695 | * @param string $content new file content |
||
| 4696 | * @return bool |
||
| 4697 | * @author Dmitry (dio) Levashov |
||
| 4698 | **/ |
||
| 4699 | abstract protected function _filePutContents($path, $content); |
||
| 4700 | |||
| 4701 | /** |
||
| 4702 | * Extract files from archive |
||
| 4703 | * |
||
| 4704 | * @param string $path file path |
||
| 4705 | * @param array $arc archiver options |
||
| 4706 | * @return bool |
||
| 4707 | * @author Dmitry (dio) Levashov, |
||
| 4708 | * @author Alexey Sukhotin |
||
| 4709 | **/ |
||
| 4710 | abstract protected function _extract($path, $arc); |
||
| 4711 | |||
| 4712 | /** |
||
| 4713 | * Create archive and return its path |
||
| 4714 | * |
||
| 4715 | * @param string $dir target dir |
||
| 4716 | * @param array $files files names list |
||
| 4717 | * @param string $name archive name |
||
| 4718 | * @param array $arc archiver options |
||
| 4719 | * @return string|bool |
||
| 4720 | * @author Dmitry (dio) Levashov, |
||
| 4721 | * @author Alexey Sukhotin |
||
| 4722 | **/ |
||
| 4723 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 4724 | |||
| 4725 | /** |
||
| 4726 | * Detect available archivers |
||
| 4727 | * |
||
| 4728 | * @return void |
||
| 4729 | * @author Dmitry (dio) Levashov, |
||
| 4730 | * @author Alexey Sukhotin |
||
| 4731 | **/ |
||
| 4732 | abstract protected function _checkArchivers(); |
||
| 4733 | |||
| 4734 | /** |
||
| 4735 | * Change file mode (chmod) |
||
| 4736 | * |
||
| 4737 | * @param string $path file path |
||
| 4738 | * @param string $mode octal string such as '0755' |
||
| 4739 | * @return bool |
||
| 4740 | * @author David Bartle, |
||
| 4741 | **/ |
||
| 4742 | abstract protected function _chmod($path, $mode); |
||
| 4743 | |||
| 4744 | |||
| 4745 | } // END class |
||
| 4746 |
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.