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) { |
||
| 698 | |||
| 699 | /** |
||
| 700 | * "Mount" volume. |
||
| 701 | * Return true if volume available for read or write, |
||
| 702 | * false - otherwise |
||
| 703 | * |
||
| 704 | * @return bool |
||
| 705 | * @author Dmitry (dio) Levashov |
||
| 706 | * @author Alexey Sukhotin |
||
| 707 | **/ |
||
| 708 | public function mount(array $opts) { |
||
| 971 | |||
| 972 | /** |
||
| 973 | * Some "unmount" stuffs - may be required by virtual fs |
||
| 974 | * |
||
| 975 | * @return void |
||
| 976 | * @author Dmitry (dio) Levashov |
||
| 977 | **/ |
||
| 978 | public function umount() { |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Return error message from last failed action |
||
| 983 | * |
||
| 984 | * @return array |
||
| 985 | * @author Dmitry (dio) Levashov |
||
| 986 | **/ |
||
| 987 | public function error() { |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
| 993 | * |
||
| 994 | * @return array |
||
| 995 | * @author Naoki Sawada |
||
| 996 | */ |
||
| 997 | public function getMimeTable() { |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Set mimetypes allowed to display to client |
||
| 1003 | * |
||
| 1004 | * @param array $mimes |
||
| 1005 | * @return void |
||
| 1006 | * @author Dmitry (dio) Levashov |
||
| 1007 | **/ |
||
| 1008 | public function setMimesFilter($mimes) { |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Return root folder hash |
||
| 1016 | * |
||
| 1017 | * @return string |
||
| 1018 | * @author Dmitry (dio) Levashov |
||
| 1019 | **/ |
||
| 1020 | public function root() { |
||
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Return target path hash |
||
| 1026 | * |
||
| 1027 | * @param string $path |
||
| 1028 | * @param string $name |
||
| 1029 | * @author Naoki Sawada |
||
| 1030 | */ |
||
| 1031 | public function getHash($path, $name = '') { |
||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * Return root or startPath hash |
||
| 1040 | * |
||
| 1041 | * @return string |
||
| 1042 | * @author Dmitry (dio) Levashov |
||
| 1043 | **/ |
||
| 1044 | public function defaultPath() { |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Return volume options required by client: |
||
| 1050 | * |
||
| 1051 | * @return array |
||
| 1052 | * @author Dmitry (dio) Levashov |
||
| 1053 | **/ |
||
| 1054 | public function options($hash) { |
||
| 1080 | |||
| 1081 | /** |
||
| 1082 | * Get option value of this volume |
||
| 1083 | * |
||
| 1084 | * @param string $name target option name |
||
| 1085 | * @return NULL|mixed target option value |
||
| 1086 | * @author Naoki Sawada |
||
| 1087 | */ |
||
| 1088 | public function getOption($name) { |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Get plugin values of this options |
||
| 1094 | * |
||
| 1095 | * @param string $name Plugin name |
||
| 1096 | * @return NULL|array Plugin values |
||
| 1097 | * @author Naoki Sawada |
||
| 1098 | */ |
||
| 1099 | public function getOptionsPlugin($name = '') { |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Return true if command disabled in options |
||
| 1109 | * |
||
| 1110 | * @param string $cmd command name |
||
| 1111 | * @return bool |
||
| 1112 | * @author Dmitry (dio) Levashov |
||
| 1113 | **/ |
||
| 1114 | public function commandDisabled($cmd) { |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Return true if mime is required mimes list |
||
| 1120 | * |
||
| 1121 | * @param string $mime mime type to check |
||
| 1122 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1123 | * @param bool|null $empty what to return on empty list |
||
| 1124 | * @return bool|null |
||
| 1125 | * @author Dmitry (dio) Levashov |
||
| 1126 | * @author Troex Nevelin |
||
| 1127 | **/ |
||
| 1128 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Return true if voume is readable. |
||
| 1142 | * |
||
| 1143 | * @return bool |
||
| 1144 | * @author Dmitry (dio) Levashov |
||
| 1145 | **/ |
||
| 1146 | public function isReadable() { |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Return true if copy from this volume allowed |
||
| 1153 | * |
||
| 1154 | * @return bool |
||
| 1155 | * @author Dmitry (dio) Levashov |
||
| 1156 | **/ |
||
| 1157 | public function copyFromAllowed() { |
||
| 1160 | |||
| 1161 | /** |
||
| 1162 | * Return file path related to root with convert encoging |
||
| 1163 | * |
||
| 1164 | * @param string $hash file hash |
||
| 1165 | * @return string |
||
| 1166 | * @author Dmitry (dio) Levashov |
||
| 1167 | **/ |
||
| 1168 | public function path($hash) { |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Return file real path if file exists |
||
| 1174 | * |
||
| 1175 | * @param string $hash file hash |
||
| 1176 | * @return string |
||
| 1177 | * @author Dmitry (dio) Levashov |
||
| 1178 | **/ |
||
| 1179 | public function realpath($hash) { |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * Return list of moved/overwrited files |
||
| 1186 | * |
||
| 1187 | * @return array |
||
| 1188 | * @author Dmitry (dio) Levashov |
||
| 1189 | **/ |
||
| 1190 | public function removed() { |
||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Clean removed files list |
||
| 1196 | * |
||
| 1197 | * @return void |
||
| 1198 | * @author Dmitry (dio) Levashov |
||
| 1199 | **/ |
||
| 1200 | public function resetRemoved() { |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * Return file/dir hash or first founded child hash with required attr == $val |
||
| 1206 | * |
||
| 1207 | * @param string $hash file hash |
||
| 1208 | * @param string $attr attribute name |
||
| 1209 | * @param bool $val attribute value |
||
| 1210 | * @return string|false |
||
| 1211 | * @author Dmitry (dio) Levashov |
||
| 1212 | **/ |
||
| 1213 | public function closest($hash, $attr, $val) { |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * Return file info or false on error |
||
| 1219 | * |
||
| 1220 | * @param string $hash file hash |
||
| 1221 | * @param bool $realpath add realpath field to file info |
||
| 1222 | * @return array|false |
||
| 1223 | * @author Dmitry (dio) Levashov |
||
| 1224 | **/ |
||
| 1225 | public function file($hash) { |
||
| 1237 | |||
| 1238 | /** |
||
| 1239 | * Return folder info |
||
| 1240 | * |
||
| 1241 | * @param string $hash folder hash |
||
| 1242 | * @param bool $hidden return hidden file info |
||
| 1243 | * @return array|false |
||
| 1244 | * @author Dmitry (dio) Levashov |
||
| 1245 | **/ |
||
| 1246 | public function dir($hash, $resolveLink=false) { |
||
| 1259 | |||
| 1260 | /** |
||
| 1261 | * Return directory content or false on error |
||
| 1262 | * |
||
| 1263 | * @param string $hash file hash |
||
| 1264 | * @return array|false |
||
| 1265 | * @author Dmitry (dio) Levashov |
||
| 1266 | **/ |
||
| 1267 | public function scandir($hash) { |
||
| 1276 | |||
| 1277 | /** |
||
| 1278 | * Return dir files names list |
||
| 1279 | * |
||
| 1280 | * @param string $hash file hash |
||
| 1281 | * @return array |
||
| 1282 | * @author Dmitry (dio) Levashov |
||
| 1283 | **/ |
||
| 1284 | public function ls($hash) { |
||
| 1300 | |||
| 1301 | /** |
||
| 1302 | * Return subfolders for required folder or false on error |
||
| 1303 | * |
||
| 1304 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1305 | * @param int $deep subdir deep |
||
| 1306 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1307 | * @return array|false |
||
| 1308 | * @author Dmitry (dio) Levashov |
||
| 1309 | **/ |
||
| 1310 | public function tree($hash='', $deep=0, $exclude='') { |
||
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Return part of dirs tree from required dir up to root dir |
||
| 1324 | * |
||
| 1325 | * @param string $hash directory hash |
||
| 1326 | * @param bool|null $lineal only lineal parents |
||
| 1327 | * @return array |
||
| 1328 | * @author Dmitry (dio) Levashov |
||
| 1329 | **/ |
||
| 1330 | public function parents($hash, $lineal = false) { |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Create thumbnail for required file and return its name of false on failed |
||
| 1360 | * |
||
| 1361 | * @return string|false |
||
| 1362 | * @author Dmitry (dio) Levashov |
||
| 1363 | **/ |
||
| 1364 | public function tmb($hash) { |
||
| 1373 | |||
| 1374 | /** |
||
| 1375 | * Return file size / total directory size |
||
| 1376 | * |
||
| 1377 | * @param string file hash |
||
| 1378 | * @return int |
||
| 1379 | * @author Dmitry (dio) Levashov |
||
| 1380 | **/ |
||
| 1381 | public function size($hash) { |
||
| 1384 | |||
| 1385 | /** |
||
| 1386 | * Open file for reading and return file pointer |
||
| 1387 | * |
||
| 1388 | * @param string file hash |
||
| 1389 | * @return Resource |
||
| 1390 | * @author Dmitry (dio) Levashov |
||
| 1391 | **/ |
||
| 1392 | public function open($hash) { |
||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Close file pointer |
||
| 1403 | * |
||
| 1404 | * @param Resource $fp file pointer |
||
| 1405 | * @param string $hash file hash |
||
| 1406 | * @return void |
||
| 1407 | * @author Dmitry (dio) Levashov |
||
| 1408 | **/ |
||
| 1409 | public function close($fp, $hash) { |
||
| 1412 | |||
| 1413 | /** |
||
| 1414 | * Create directory and return dir info |
||
| 1415 | * |
||
| 1416 | * @param string $dsthash destination directory hash |
||
| 1417 | * @param string $name directory name |
||
| 1418 | * @return array|false |
||
| 1419 | * @author Dmitry (dio) Levashov |
||
| 1420 | **/ |
||
| 1421 | public function mkdir($dsthash, $name) { |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Create empty file and return its info |
||
| 1451 | * |
||
| 1452 | * @param string $dst destination directory |
||
| 1453 | * @param string $name file name |
||
| 1454 | * @return array|false |
||
| 1455 | * @author Dmitry (dio) Levashov |
||
| 1456 | **/ |
||
| 1457 | public function mkfile($dst, $name) { |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * Rename file and return file info |
||
| 1486 | * |
||
| 1487 | * @param string $hash file hash |
||
| 1488 | * @param string $name new file name |
||
| 1489 | * @return array|false |
||
| 1490 | * @author Dmitry (dio) Levashov |
||
| 1491 | **/ |
||
| 1492 | public function rename($hash, $name) { |
||
| 1538 | |||
| 1539 | /** |
||
| 1540 | * Create file copy with suffix "copy number" and return its info |
||
| 1541 | * |
||
| 1542 | * @param string $hash file hash |
||
| 1543 | * @param string $suffix suffix to add to file name |
||
| 1544 | * @return array|false |
||
| 1545 | * @author Dmitry (dio) Levashov |
||
| 1546 | **/ |
||
| 1547 | public function duplicate($hash, $suffix='copy') { |
||
| 1568 | |||
| 1569 | /** |
||
| 1570 | * Save uploaded file. |
||
| 1571 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
| 1572 | * |
||
| 1573 | * @param Resource $fp file pointer |
||
| 1574 | * @param string $dst destination folder hash |
||
| 1575 | * @param string $src file name |
||
| 1576 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 1577 | * @return array|false |
||
| 1578 | * @author Dmitry (dio) Levashov |
||
| 1579 | **/ |
||
| 1580 | public function upload($fp, $dst, $name, $tmpname) { |
||
| 1656 | |||
| 1657 | /** |
||
| 1658 | * Paste files |
||
| 1659 | * |
||
| 1660 | * @param Object $volume source volume |
||
| 1661 | * @param string $source file hash |
||
| 1662 | * @param string $dst destination dir hash |
||
| 1663 | * @param bool $rmSrc remove source after copy? |
||
| 1664 | * @return array|false |
||
| 1665 | * @author Dmitry (dio) Levashov |
||
| 1666 | **/ |
||
| 1667 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
| 1755 | |||
| 1756 | /** |
||
| 1757 | * Return file contents |
||
| 1758 | * |
||
| 1759 | * @param string $hash file hash |
||
| 1760 | * @return string|false |
||
| 1761 | * @author Dmitry (dio) Levashov |
||
| 1762 | **/ |
||
| 1763 | public function getContents($hash) { |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * Put content in text file and return file info. |
||
| 1783 | * |
||
| 1784 | * @param string $hash file hash |
||
| 1785 | * @param string $content new file content |
||
| 1786 | * @return array |
||
| 1787 | * @author Dmitry (dio) Levashov |
||
| 1788 | **/ |
||
| 1789 | public function putContents($hash, $content) { |
||
| 1824 | |||
| 1825 | /** |
||
| 1826 | * Extract files from archive |
||
| 1827 | * |
||
| 1828 | * @param string $hash archive hash |
||
| 1829 | * @return array|bool |
||
| 1830 | * @author Dmitry (dio) Levashov, |
||
| 1831 | * @author Alexey Sukhotin |
||
| 1832 | **/ |
||
| 1833 | public function extract($hash, $makedir = null) { |
||
| 1872 | |||
| 1873 | /** |
||
| 1874 | * Add files to archive |
||
| 1875 | * |
||
| 1876 | * @return void |
||
| 1877 | **/ |
||
| 1878 | public function archive($hashes, $mime, $name = '') { |
||
| 1922 | |||
| 1923 | /** |
||
| 1924 | * Resize image |
||
| 1925 | * |
||
| 1926 | * @param string $hash image file |
||
| 1927 | * @param int $width new width |
||
| 1928 | * @param int $height new height |
||
| 1929 | * @param int $x X start poistion for crop |
||
| 1930 | * @param int $y Y start poistion for crop |
||
| 1931 | * @param string $mode action how to mainpulate image |
||
| 1932 | * @return array|false |
||
| 1933 | * @author Dmitry (dio) Levashov |
||
| 1934 | * @author Alexey Sukhotin |
||
| 1935 | * @author nao-pon |
||
| 1936 | * @author Troex Nevelin |
||
| 1937 | **/ |
||
| 1938 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0) { |
||
| 2025 | |||
| 2026 | /** |
||
| 2027 | * Remove file/dir |
||
| 2028 | * |
||
| 2029 | * @param string $hash file hash |
||
| 2030 | * @return bool |
||
| 2031 | * @author Dmitry (dio) Levashov |
||
| 2032 | **/ |
||
| 2033 | public function rm($hash) { |
||
| 2038 | |||
| 2039 | /** |
||
| 2040 | * Search files |
||
| 2041 | * |
||
| 2042 | * @param string $q search string |
||
| 2043 | * @param array $mimes |
||
| 2044 | * @return array |
||
| 2045 | * @author Dmitry (dio) Levashov |
||
| 2046 | **/ |
||
| 2047 | public function search($q, $mimes, $hash = null) { |
||
| 2066 | |||
| 2067 | /** |
||
| 2068 | * Return image dimensions |
||
| 2069 | * |
||
| 2070 | * @param string $hash file hash |
||
| 2071 | * @return array |
||
| 2072 | * @author Dmitry (dio) Levashov |
||
| 2073 | **/ |
||
| 2074 | public function dimensions($hash) { |
||
| 2081 | |||
| 2082 | /** |
||
| 2083 | * Return content URL (for netmout volume driver) |
||
| 2084 | * If file.url == 1 requests from JavaScript client with XHR |
||
| 2085 | * |
||
| 2086 | * @param string $hash file hash |
||
| 2087 | * @param array $options options array |
||
| 2088 | * @return boolean|string |
||
| 2089 | * @author Naoki Sawada |
||
| 2090 | */ |
||
| 2091 | public function getContentUrl($hash, $options = array()) { |
||
| 2097 | |||
| 2098 | /** |
||
| 2099 | * Return temp path |
||
| 2100 | * |
||
| 2101 | * @return string |
||
| 2102 | * @author Naoki Sawada |
||
| 2103 | */ |
||
| 2104 | public function getTempPath() { |
||
| 2117 | |||
| 2118 | /** |
||
| 2119 | * (Make &) Get upload taget dirctory hash |
||
| 2120 | * |
||
| 2121 | * @param string $baseTargetHash |
||
| 2122 | * @param string $path |
||
| 2123 | * @param array $result |
||
| 2124 | * @return boolean|string |
||
| 2125 | * @author Naoki Sawada |
||
| 2126 | */ |
||
| 2127 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
| 2154 | |||
| 2155 | /** |
||
| 2156 | * Return this uploadMaxSize value |
||
| 2157 | * |
||
| 2158 | * @return integer |
||
| 2159 | * @author Naoki Sawada |
||
| 2160 | */ |
||
| 2161 | public function getUploadMaxSize() { |
||
| 2164 | |||
| 2165 | /** |
||
| 2166 | * Save error message |
||
| 2167 | * |
||
| 2168 | * @param array error |
||
| 2169 | * @return false |
||
| 2170 | * @author Dmitry(dio) Levashov |
||
| 2171 | **/ |
||
| 2172 | protected function setError($error) { |
||
| 2187 | |||
| 2188 | /*********************************************************************/ |
||
| 2189 | /* FS API */ |
||
| 2190 | /*********************************************************************/ |
||
| 2191 | |||
| 2192 | /***************** server encoding support *******************/ |
||
| 2193 | |||
| 2194 | /** |
||
| 2195 | * Return parent directory path (with convert encording) |
||
| 2196 | * |
||
| 2197 | * @param string $path file path |
||
| 2198 | * @return string |
||
| 2199 | * @author Naoki Sawada |
||
| 2200 | **/ |
||
| 2201 | protected function dirnameCE($path) { |
||
| 2204 | |||
| 2205 | /** |
||
| 2206 | * Return file name (with convert encording) |
||
| 2207 | * |
||
| 2208 | * @param string $path file path |
||
| 2209 | * @return string |
||
| 2210 | * @author Naoki Sawada |
||
| 2211 | **/ |
||
| 2212 | protected function basenameCE($path) { |
||
| 2215 | |||
| 2216 | /** |
||
| 2217 | * Join dir name and file name and return full path. (with convert encording) |
||
| 2218 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 2219 | * |
||
| 2220 | * @param string $dir dir path |
||
| 2221 | * @param string $name file name |
||
| 2222 | * @return string |
||
| 2223 | * @author Naoki Sawada |
||
| 2224 | **/ |
||
| 2225 | protected function joinPathCE($dir, $name) { |
||
| 2228 | |||
| 2229 | /** |
||
| 2230 | * Return normalized path (with convert encording) |
||
| 2231 | * |
||
| 2232 | * @param string $path file path |
||
| 2233 | * @return string |
||
| 2234 | * @author Naoki Sawada |
||
| 2235 | **/ |
||
| 2236 | protected function normpathCE($path) { |
||
| 2239 | |||
| 2240 | /** |
||
| 2241 | * Return file path related to root dir (with convert encording) |
||
| 2242 | * |
||
| 2243 | * @param string $path file path |
||
| 2244 | * @return string |
||
| 2245 | * @author Naoki Sawada |
||
| 2246 | **/ |
||
| 2247 | protected function relpathCE($path) { |
||
| 2250 | |||
| 2251 | /** |
||
| 2252 | * Convert path related to root dir into real path (with convert encording) |
||
| 2253 | * |
||
| 2254 | * @param string $path rel file path |
||
| 2255 | * @return string |
||
| 2256 | * @author Naoki Sawada |
||
| 2257 | **/ |
||
| 2258 | protected function abspathCE($path) { |
||
| 2261 | |||
| 2262 | /** |
||
| 2263 | * Return true if $path is children of $parent (with convert encording) |
||
| 2264 | * |
||
| 2265 | * @param string $path path to check |
||
| 2266 | * @param string $parent parent path |
||
| 2267 | * @return bool |
||
| 2268 | * @author Naoki Sawada |
||
| 2269 | **/ |
||
| 2270 | protected function inpathCE($path, $parent) { |
||
| 2273 | |||
| 2274 | /** |
||
| 2275 | * Open file and return file pointer (with convert encording) |
||
| 2276 | * |
||
| 2277 | * @param string $path file path |
||
| 2278 | * @param bool $write open file for writing |
||
| 2279 | * @return resource|false |
||
| 2280 | * @author Naoki Sawada |
||
| 2281 | **/ |
||
| 2282 | protected function fopenCE($path, $mode='rb') { |
||
| 2285 | |||
| 2286 | /** |
||
| 2287 | * Close opened file (with convert encording) |
||
| 2288 | * |
||
| 2289 | * @param resource $fp file pointer |
||
| 2290 | * @param string $path file path |
||
| 2291 | * @return bool |
||
| 2292 | * @author Naoki Sawada |
||
| 2293 | **/ |
||
| 2294 | protected function fcloseCE($fp, $path='') { |
||
| 2297 | |||
| 2298 | /** |
||
| 2299 | * Create new file and write into it from file pointer. (with convert encording) |
||
| 2300 | * Return new file path or false on error. |
||
| 2301 | * |
||
| 2302 | * @param resource $fp file pointer |
||
| 2303 | * @param string $dir target dir path |
||
| 2304 | * @param string $name file name |
||
| 2305 | * @param array $stat file stat (required by some virtual fs) |
||
| 2306 | * @return bool|string |
||
| 2307 | * @author Naoki Sawada |
||
| 2308 | **/ |
||
| 2309 | protected function saveCE($fp, $dir, $name, $stat) { |
||
| 2312 | |||
| 2313 | /** |
||
| 2314 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
| 2315 | * |
||
| 2316 | * @param string $path dir path |
||
| 2317 | * @return bool |
||
| 2318 | * @author Naoki Sawada |
||
| 2319 | **/ |
||
| 2320 | protected function subdirsCE($path) { |
||
| 2326 | |||
| 2327 | /** |
||
| 2328 | * Return files list in directory (with convert encording) |
||
| 2329 | * |
||
| 2330 | * @param string $path dir path |
||
| 2331 | * @return array |
||
| 2332 | * @author Naoki Sawada |
||
| 2333 | **/ |
||
| 2334 | protected function scandirCE($path) { |
||
| 2337 | |||
| 2338 | /** |
||
| 2339 | * Create symlink (with convert encording) |
||
| 2340 | * |
||
| 2341 | * @param string $source file to link to |
||
| 2342 | * @param string $targetDir folder to create link in |
||
| 2343 | * @param string $name symlink name |
||
| 2344 | * @return bool |
||
| 2345 | * @author Naoki Sawada |
||
| 2346 | **/ |
||
| 2347 | protected function symlinkCE($source, $targetDir, $name) { |
||
| 2350 | |||
| 2351 | /***************** paths *******************/ |
||
| 2352 | |||
| 2353 | /** |
||
| 2354 | * Encode path into hash |
||
| 2355 | * |
||
| 2356 | * @param string file path |
||
| 2357 | * @return string |
||
| 2358 | * @author Dmitry (dio) Levashov |
||
| 2359 | * @author Troex Nevelin |
||
| 2360 | **/ |
||
| 2361 | protected function encode($path) { |
||
| 2382 | |||
| 2383 | /** |
||
| 2384 | * Decode path from hash |
||
| 2385 | * |
||
| 2386 | * @param string file hash |
||
| 2387 | * @return string |
||
| 2388 | * @author Dmitry (dio) Levashov |
||
| 2389 | * @author Troex Nevelin |
||
| 2390 | **/ |
||
| 2391 | protected function decode($hash) { |
||
| 2403 | |||
| 2404 | /** |
||
| 2405 | * Return crypted path |
||
| 2406 | * Not implemented |
||
| 2407 | * |
||
| 2408 | * @param string path |
||
| 2409 | * @return mixed |
||
| 2410 | * @author Dmitry (dio) Levashov |
||
| 2411 | **/ |
||
| 2412 | protected function crypt($path) { |
||
| 2415 | |||
| 2416 | /** |
||
| 2417 | * Return uncrypted path |
||
| 2418 | * Not implemented |
||
| 2419 | * |
||
| 2420 | * @param mixed hash |
||
| 2421 | * @return mixed |
||
| 2422 | * @author Dmitry (dio) Levashov |
||
| 2423 | **/ |
||
| 2424 | protected function uncrypt($hash) { |
||
| 2427 | |||
| 2428 | /** |
||
| 2429 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
| 2430 | * |
||
| 2431 | * @param string $name file name |
||
| 2432 | * @return bool |
||
| 2433 | * @author Dmitry (dio) Levashov |
||
| 2434 | **/ |
||
| 2435 | protected function nameAccepted($name) { |
||
| 2447 | |||
| 2448 | /** |
||
| 2449 | * Return new unique name based on file name and suffix |
||
| 2450 | * |
||
| 2451 | * @param string $path file path |
||
| 2452 | * @param string $suffix suffix append to name |
||
| 2453 | * @return string |
||
| 2454 | * @author Dmitry (dio) Levashov |
||
| 2455 | **/ |
||
| 2456 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { |
||
| 2484 | |||
| 2485 | /** |
||
| 2486 | * Converts character encoding from UTF-8 to server's one |
||
| 2487 | * |
||
| 2488 | * @param mixed $var target string or array var |
||
| 2489 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 2490 | * @param string $unknown replaces character for unknown |
||
| 2491 | * @return mixed |
||
| 2492 | * @author Naoki Sawada |
||
| 2493 | */ |
||
| 2494 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
| 2497 | |||
| 2498 | /** |
||
| 2499 | * Converts character encoding from server's one to UTF-8 |
||
| 2500 | * |
||
| 2501 | * @param mixed $var target string or array var |
||
| 2502 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 2503 | * @param string $unknown replaces character for unknown |
||
| 2504 | * @return mixed |
||
| 2505 | * @author Naoki Sawada |
||
| 2506 | */ |
||
| 2507 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
| 2510 | |||
| 2511 | /** |
||
| 2512 | * Converts character encoding (base function) |
||
| 2513 | * |
||
| 2514 | * @param mixed $var target string or array var |
||
| 2515 | * @param string $from from character encoding |
||
| 2516 | * @param string $to to character encoding |
||
| 2517 | * @param string $locale local locale |
||
| 2518 | * @param string $unknown replaces character for unknown |
||
| 2519 | * @return mixed |
||
| 2520 | */ |
||
| 2521 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
| 2550 | |||
| 2551 | /*********************** util mainly for inheritance class *********************/ |
||
| 2552 | |||
| 2553 | /** |
||
| 2554 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 2555 | * When needing the unique file to a path, give $path to parameter. |
||
| 2556 | * |
||
| 2557 | * @param string $path for get unique file to a path |
||
| 2558 | * @return string|false |
||
| 2559 | * @author Naoki Sawada |
||
| 2560 | */ |
||
| 2561 | protected function getTempFile($path = '') { |
||
| 2587 | |||
| 2588 | /** |
||
| 2589 | * File path of local server side work file path |
||
| 2590 | * |
||
| 2591 | * @param string $path path need convert encoding to server encoding |
||
| 2592 | * @return string |
||
| 2593 | * @author Naoki Sawada |
||
| 2594 | */ |
||
| 2595 | protected function getWorkFile($path) { |
||
| 2610 | |||
| 2611 | /** |
||
| 2612 | * Get image size array with `dimensions` |
||
| 2613 | * |
||
| 2614 | * @param string $path path need convert encoding to server encoding |
||
| 2615 | * @param string $mime file mime type |
||
| 2616 | * @return array|false |
||
| 2617 | */ |
||
| 2618 | public function getImageSize($path, $mime = '') { |
||
| 2630 | |||
| 2631 | /** |
||
| 2632 | * Delete dirctory trees |
||
| 2633 | * |
||
| 2634 | * @param string $localpath path need convert encoding to server encoding |
||
| 2635 | * @return boolean |
||
| 2636 | * @author Naoki Sawada |
||
| 2637 | */ |
||
| 2638 | protected function delTree($localpath) { |
||
| 2647 | |||
| 2648 | /*********************** file stat *********************/ |
||
| 2649 | |||
| 2650 | /** |
||
| 2651 | * Check file attribute |
||
| 2652 | * |
||
| 2653 | * @param string $path file path |
||
| 2654 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 2655 | * @param bool $val attribute value returned by file system |
||
| 2656 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 2657 | * @return bool |
||
| 2658 | * @author Dmitry (dio) Levashov |
||
| 2659 | **/ |
||
| 2660 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
| 2694 | |||
| 2695 | /** |
||
| 2696 | * Return true if file with given name can be created in given folder. |
||
| 2697 | * |
||
| 2698 | * @param string $dir parent dir path |
||
| 2699 | * @param string $name new file name |
||
| 2700 | * @return bool |
||
| 2701 | * @author Dmitry (dio) Levashov |
||
| 2702 | **/ |
||
| 2703 | protected function allowCreate($dir, $name, $isDir = null) { |
||
| 2726 | |||
| 2727 | /** |
||
| 2728 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 2729 | * |
||
| 2730 | * @param string $mime |
||
| 2731 | * @return boolean |
||
| 2732 | */ |
||
| 2733 | protected function allowPutMime($mime) { |
||
| 2751 | |||
| 2752 | /** |
||
| 2753 | * Return fileinfo |
||
| 2754 | * |
||
| 2755 | * @param string $path file cache |
||
| 2756 | * @return array |
||
| 2757 | * @author Dmitry (dio) Levashov |
||
| 2758 | **/ |
||
| 2759 | protected function stat($path) { |
||
| 2786 | |||
| 2787 | /** |
||
| 2788 | * Put file stat in cache and return it |
||
| 2789 | * |
||
| 2790 | * @param string $path file path |
||
| 2791 | * @param array $stat file stat |
||
| 2792 | * @return array |
||
| 2793 | * @author Dmitry (dio) Levashov |
||
| 2794 | **/ |
||
| 2795 | protected function updateCache($path, $stat) { |
||
| 2934 | |||
| 2935 | /** |
||
| 2936 | * Get stat for folder content and put in cache |
||
| 2937 | * |
||
| 2938 | * @param string $path |
||
| 2939 | * @return void |
||
| 2940 | * @author Dmitry (dio) Levashov |
||
| 2941 | **/ |
||
| 2942 | protected function cacheDir($path) { |
||
| 2955 | |||
| 2956 | /** |
||
| 2957 | * Clean cache |
||
| 2958 | * |
||
| 2959 | * @return void |
||
| 2960 | * @author Dmitry (dio) Levashov |
||
| 2961 | **/ |
||
| 2962 | protected function clearcache() { |
||
| 2966 | |||
| 2967 | /** |
||
| 2968 | * Return file mimetype |
||
| 2969 | * |
||
| 2970 | * @param string $path file path |
||
| 2971 | * @return string |
||
| 2972 | * @author Dmitry (dio) Levashov |
||
| 2973 | **/ |
||
| 2974 | protected function mimetype($path, $name = '') { |
||
| 3019 | |||
| 3020 | /** |
||
| 3021 | * Detect file mimetype using "internal" method |
||
| 3022 | * |
||
| 3023 | * @param string $path file path |
||
| 3024 | * @return string |
||
| 3025 | * @author Dmitry (dio) Levashov |
||
| 3026 | **/ |
||
| 3027 | static protected function mimetypeInternalDetect($path) { |
||
| 3033 | |||
| 3034 | /** |
||
| 3035 | * Return file/total directory size |
||
| 3036 | * |
||
| 3037 | * @param string $path file path |
||
| 3038 | * @return int |
||
| 3039 | * @author Dmitry (dio) Levashov |
||
| 3040 | **/ |
||
| 3041 | protected function countSize($path) { |
||
| 3066 | |||
| 3067 | /** |
||
| 3068 | * Return true if all mimes is directory or files |
||
| 3069 | * |
||
| 3070 | * @param string $mime1 mimetype |
||
| 3071 | * @param string $mime2 mimetype |
||
| 3072 | * @return bool |
||
| 3073 | * @author Dmitry (dio) Levashov |
||
| 3074 | **/ |
||
| 3075 | protected function isSameType($mime1, $mime2) { |
||
| 3078 | |||
| 3079 | /** |
||
| 3080 | * If file has required attr == $val - return file path, |
||
| 3081 | * If dir has child with has required attr == $val - return child path |
||
| 3082 | * |
||
| 3083 | * @param string $path file path |
||
| 3084 | * @param string $attr attribute name |
||
| 3085 | * @param bool $val attribute value |
||
| 3086 | * @return string|false |
||
| 3087 | * @author Dmitry (dio) Levashov |
||
| 3088 | **/ |
||
| 3089 | protected function closestByAttr($path, $attr, $val) { |
||
| 3106 | |||
| 3107 | /** |
||
| 3108 | * Return first found children with required attr == $val |
||
| 3109 | * |
||
| 3110 | * @param string $path file path |
||
| 3111 | * @param string $attr attribute name |
||
| 3112 | * @param bool $val attribute value |
||
| 3113 | * @return string|false |
||
| 3114 | * @author Dmitry (dio) Levashov |
||
| 3115 | **/ |
||
| 3116 | protected function childsByAttr($path, $attr, $val) { |
||
| 3124 | |||
| 3125 | /***************** get content *******************/ |
||
| 3126 | |||
| 3127 | /** |
||
| 3128 | * Return required dir's files info. |
||
| 3129 | * If onlyMimes is set - return only dirs and files of required mimes |
||
| 3130 | * |
||
| 3131 | * @param string $path dir path |
||
| 3132 | * @return array |
||
| 3133 | * @author Dmitry (dio) Levashov |
||
| 3134 | **/ |
||
| 3135 | protected function getScandir($path) { |
||
| 3148 | |||
| 3149 | |||
| 3150 | /** |
||
| 3151 | * Return subdirs tree |
||
| 3152 | * |
||
| 3153 | * @param string $path parent dir path |
||
| 3154 | * @param int $deep tree deep |
||
| 3155 | * @return array |
||
| 3156 | * @author Dmitry (dio) Levashov |
||
| 3157 | **/ |
||
| 3158 | protected function gettree($path, $deep, $exclude='') { |
||
| 3176 | |||
| 3177 | /** |
||
| 3178 | * Recursive files search |
||
| 3179 | * |
||
| 3180 | * @param string $path dir path |
||
| 3181 | * @param string $q search string |
||
| 3182 | * @param array $mimes |
||
| 3183 | * @return array |
||
| 3184 | * @author Dmitry (dio) Levashov |
||
| 3185 | **/ |
||
| 3186 | protected function doSearch($path, $q, $mimes) { |
||
| 3222 | |||
| 3223 | /********************** manuipulations ******************/ |
||
| 3224 | |||
| 3225 | /** |
||
| 3226 | * Copy file/recursive copy dir only in current volume. |
||
| 3227 | * Return new file path or false. |
||
| 3228 | * |
||
| 3229 | * @param string $src source path |
||
| 3230 | * @param string $dst destination dir path |
||
| 3231 | * @param string $name new file name (optionaly) |
||
| 3232 | * @return string|false |
||
| 3233 | * @author Dmitry (dio) Levashov |
||
| 3234 | **/ |
||
| 3235 | protected function copy($src, $dst, $name) { |
||
| 3277 | |||
| 3278 | /** |
||
| 3279 | * Move file |
||
| 3280 | * Return new file path or false. |
||
| 3281 | * |
||
| 3282 | * @param string $src source path |
||
| 3283 | * @param string $dst destination dir path |
||
| 3284 | * @param string $name new file name |
||
| 3285 | * @return string|false |
||
| 3286 | * @author Dmitry (dio) Levashov |
||
| 3287 | **/ |
||
| 3288 | protected function move($src, $dst, $name) { |
||
| 3302 | |||
| 3303 | /** |
||
| 3304 | * Copy file from another volume. |
||
| 3305 | * Return new file path or false. |
||
| 3306 | * |
||
| 3307 | * @param Object $volume source volume |
||
| 3308 | * @param string $src source file hash |
||
| 3309 | * @param string $destination destination dir path |
||
| 3310 | * @param string $name file name |
||
| 3311 | * @return string|false |
||
| 3312 | * @author Dmitry (dio) Levashov |
||
| 3313 | **/ |
||
| 3314 | protected function copyFrom($volume, $src, $destination, $name) { |
||
| 3376 | |||
| 3377 | /** |
||
| 3378 | * Remove file/ recursive remove dir |
||
| 3379 | * |
||
| 3380 | * @param string $path file path |
||
| 3381 | * @param bool $force try to remove even if file locked |
||
| 3382 | * @return bool |
||
| 3383 | * @author Dmitry (dio) Levashov |
||
| 3384 | **/ |
||
| 3385 | protected function remove($path, $force = false) { |
||
| 3415 | |||
| 3416 | |||
| 3417 | /************************* thumbnails **************************/ |
||
| 3418 | |||
| 3419 | /** |
||
| 3420 | * Return thumbnail file name for required file |
||
| 3421 | * |
||
| 3422 | * @param array $stat file stat |
||
| 3423 | * @return string |
||
| 3424 | * @author Dmitry (dio) Levashov |
||
| 3425 | **/ |
||
| 3426 | protected function tmbname($stat) { |
||
| 3429 | |||
| 3430 | /** |
||
| 3431 | * Return thumnbnail name if exists |
||
| 3432 | * |
||
| 3433 | * @param string $path file path |
||
| 3434 | * @param array $stat file stat |
||
| 3435 | * @return string|false |
||
| 3436 | * @author Dmitry (dio) Levashov |
||
| 3437 | **/ |
||
| 3438 | protected function gettmb($path, $stat) { |
||
| 3452 | |||
| 3453 | /** |
||
| 3454 | * Return true if thumnbnail for required file can be created |
||
| 3455 | * |
||
| 3456 | * @param string $path thumnbnail path |
||
| 3457 | * @param array $stat file stat |
||
| 3458 | * @param bool $checkTmbPath |
||
| 3459 | * @return string|bool |
||
| 3460 | * @author Dmitry (dio) Levashov |
||
| 3461 | **/ |
||
| 3462 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
| 3469 | |||
| 3470 | /** |
||
| 3471 | * Return true if required file can be resized. |
||
| 3472 | * By default - the same as canCreateTmb |
||
| 3473 | * |
||
| 3474 | * @param string $path thumnbnail path |
||
| 3475 | * @param array $stat file stat |
||
| 3476 | * @return string|bool |
||
| 3477 | * @author Dmitry (dio) Levashov |
||
| 3478 | **/ |
||
| 3479 | protected function canResize($path, $stat) { |
||
| 3482 | |||
| 3483 | /** |
||
| 3484 | * Create thumnbnail and return it's URL on success |
||
| 3485 | * |
||
| 3486 | * @param string $path file path |
||
| 3487 | * @param string $mime file mime type |
||
| 3488 | * @return string|false |
||
| 3489 | * @author Dmitry (dio) Levashov |
||
| 3490 | **/ |
||
| 3491 | protected function createTmb($path, $stat) { |
||
| 3561 | |||
| 3562 | /** |
||
| 3563 | * Resize image |
||
| 3564 | * |
||
| 3565 | * @param string $path image file |
||
| 3566 | * @param int $width new width |
||
| 3567 | * @param int $height new height |
||
| 3568 | * @param bool $keepProportions crop image |
||
| 3569 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 3570 | * @param string $destformat image destination format |
||
| 3571 | * @return string|false |
||
| 3572 | * @author Dmitry (dio) Levashov |
||
| 3573 | * @author Alexey Sukhotin |
||
| 3574 | **/ |
||
| 3575 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null) { |
||
| 3668 | |||
| 3669 | /** |
||
| 3670 | * Crop image |
||
| 3671 | * |
||
| 3672 | * @param string $path image file |
||
| 3673 | * @param int $width crop width |
||
| 3674 | * @param int $height crop height |
||
| 3675 | * @param bool $x crop left offset |
||
| 3676 | * @param bool $y crop top offset |
||
| 3677 | * @param string $destformat image destination format |
||
| 3678 | * @return string|false |
||
| 3679 | * @author Dmitry (dio) Levashov |
||
| 3680 | * @author Alexey Sukhotin |
||
| 3681 | **/ |
||
| 3682 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null) { |
||
| 3756 | |||
| 3757 | /** |
||
| 3758 | * Put image to square |
||
| 3759 | * |
||
| 3760 | * @param string $path image file |
||
| 3761 | * @param int $width square width |
||
| 3762 | * @param int $height square height |
||
| 3763 | * @param int $align reserved |
||
| 3764 | * @param int $valign reserved |
||
| 3765 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3766 | * @param string $destformat image destination format |
||
| 3767 | * @return string|false |
||
| 3768 | * @author Dmitry (dio) Levashov |
||
| 3769 | * @author Alexey Sukhotin |
||
| 3770 | **/ |
||
| 3771 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null) { |
||
| 3849 | |||
| 3850 | /** |
||
| 3851 | * Rotate image |
||
| 3852 | * |
||
| 3853 | * @param string $path image file |
||
| 3854 | * @param int $degree rotete degrees |
||
| 3855 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3856 | * @param string $destformat image destination format |
||
| 3857 | * @return string|false |
||
| 3858 | * @author nao-pon |
||
| 3859 | * @author Troex Nevelin |
||
| 3860 | **/ |
||
| 3861 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null) { |
||
| 3941 | |||
| 3942 | /** |
||
| 3943 | * Execute shell command |
||
| 3944 | * |
||
| 3945 | * @param string $command command line |
||
| 3946 | * @param array $output stdout strings |
||
| 3947 | * @param array $return_var process exit code |
||
| 3948 | * @param array $error_output stderr strings |
||
| 3949 | * @return int exit code |
||
| 3950 | * @author Alexey Sukhotin |
||
| 3951 | **/ |
||
| 3952 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
| 3982 | |||
| 3983 | /** |
||
| 3984 | * Remove thumbnail, also remove recursively if stat is directory |
||
| 3985 | * |
||
| 3986 | * @param string $stat file stat |
||
| 3987 | * @return void |
||
| 3988 | * @author Dmitry (dio) Levashov |
||
| 3989 | * @author Naoki Sawada |
||
| 3990 | * @author Troex Nevelin |
||
| 3991 | **/ |
||
| 3992 | protected function rmTmb($stat) { |
||
| 4005 | |||
| 4006 | /** |
||
| 4007 | * Create an gd image according to the specified mime type |
||
| 4008 | * |
||
| 4009 | * @param string $path image file |
||
| 4010 | * @param string $mime |
||
| 4011 | * @return gd image resource identifier |
||
| 4012 | */ |
||
| 4013 | protected function gdImageCreate($path,$mime){ |
||
| 4029 | |||
| 4030 | /** |
||
| 4031 | * Output gd image to file |
||
| 4032 | * |
||
| 4033 | * @param resource $image gd image resource |
||
| 4034 | * @param string $filename The path to save the file to. |
||
| 4035 | * @param string $destformat The Image type to use for $filename |
||
| 4036 | * @param string $mime The original image mime type |
||
| 4037 | */ |
||
| 4038 | protected function gdImage($image, $filename, $destformat, $mime ){ |
||
| 4050 | |||
| 4051 | /** |
||
| 4052 | * Assign the proper background to a gd image |
||
| 4053 | * |
||
| 4054 | * @param resource $image gd image resource |
||
| 4055 | * @param string $bgcolor background color in #rrggbb format |
||
| 4056 | */ |
||
| 4057 | protected function gdImageBackground($image, $bgcolor){ |
||
| 4070 | |||
| 4071 | /*********************** misc *************************/ |
||
| 4072 | |||
| 4073 | /** |
||
| 4074 | * Return smart formatted date |
||
| 4075 | * |
||
| 4076 | * @param int $ts file timestamp |
||
| 4077 | * @return string |
||
| 4078 | * @author Dmitry (dio) Levashov |
||
| 4079 | **/ |
||
| 4080 | // protected function formatDate($ts) { |
||
| 4081 | // if ($ts > $this->today) { |
||
| 4082 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 4083 | // } |
||
| 4084 | // |
||
| 4085 | // if ($ts > $this->yesterday) { |
||
| 4086 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 4087 | // } |
||
| 4088 | // |
||
| 4089 | // return date($this->options['dateFormat'], $ts); |
||
| 4090 | // } |
||
| 4091 | |||
| 4092 | /** |
||
| 4093 | * Find position of first occurrence of string in a string with multibyte support |
||
| 4094 | * |
||
| 4095 | * @param string $haystack The string being checked. |
||
| 4096 | * @param string $needle The string to find in haystack. |
||
| 4097 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 4098 | * @return int|bool |
||
| 4099 | * @author Alexey Sukhotin |
||
| 4100 | **/ |
||
| 4101 | protected function stripos($haystack , $needle , $offset = 0) { |
||
| 4109 | |||
| 4110 | /** |
||
| 4111 | * Get server side available archivers |
||
| 4112 | * |
||
| 4113 | * @param bool $use_cache |
||
| 4114 | * @return array |
||
| 4115 | */ |
||
| 4116 | protected function getArchivers($use_cache = true) { |
||
| 4232 | |||
| 4233 | /** |
||
| 4234 | * Resolve relative / (Unix-like)absolute path |
||
| 4235 | * |
||
| 4236 | * @param string $path target path |
||
| 4237 | * @param string $base base path |
||
| 4238 | * @return string |
||
| 4239 | */ |
||
| 4240 | protected function getFullPath($path, $base) { |
||
| 4287 | |||
| 4288 | /** |
||
| 4289 | * Remove directory recursive on local file system |
||
| 4290 | * |
||
| 4291 | * @param string $dir Target dirctory path |
||
| 4292 | * @return boolean |
||
| 4293 | * @author Naoki Sawada |
||
| 4294 | */ |
||
| 4295 | public function rmdirRecursive($dir) { |
||
| 4315 | |||
| 4316 | /** |
||
| 4317 | * Create archive and return its path |
||
| 4318 | * |
||
| 4319 | * @param string $dir target dir |
||
| 4320 | * @param array $files files names list |
||
| 4321 | * @param string $name archive name |
||
| 4322 | * @param array $arc archiver options |
||
| 4323 | * @return string|bool |
||
| 4324 | * @author Dmitry (dio) Levashov, |
||
| 4325 | * @author Alexey Sukhotin |
||
| 4326 | * @author Naoki Sawada |
||
| 4327 | **/ |
||
| 4328 | protected function makeArchive($dir, $files, $name, $arc) { |
||
| 4346 | |||
| 4347 | /** |
||
| 4348 | * Unpack archive |
||
| 4349 | * |
||
| 4350 | * @param string $path archive path |
||
| 4351 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 4352 | * @param bool $remove remove archive ( unlink($path) ) |
||
| 4353 | * @return void |
||
| 4354 | * @author Dmitry (dio) Levashov |
||
| 4355 | * @author Alexey Sukhotin |
||
| 4356 | * @author Naoki Sawada |
||
| 4357 | **/ |
||
| 4358 | protected function unpackArchive($path, $arc, $remove = true) { |
||
| 4373 | |||
| 4374 | /** |
||
| 4375 | * Create Zip archive using PHP class ZipArchive |
||
| 4376 | * |
||
| 4377 | * @param string $dir target dir |
||
| 4378 | * @param array $files files names list |
||
| 4379 | * @param string|object $zipPath Zip archive name |
||
| 4380 | * @return void |
||
| 4381 | * @author Naoki Sawada |
||
| 4382 | */ |
||
| 4383 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
| 4421 | |||
| 4422 | /** |
||
| 4423 | * Unpack Zip archive using PHP class ZipArchive |
||
| 4424 | * |
||
| 4425 | * @param string $zipPath Zip archive name |
||
| 4426 | * @param string $toDir Extract to path |
||
| 4427 | * @return bool |
||
| 4428 | * @author Naoki Sawada |
||
| 4429 | */ |
||
| 4430 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
| 4442 | |||
| 4443 | /**==================================* abstract methods *====================================**/ |
||
| 4444 | |||
| 4445 | /*********************** paths/urls *************************/ |
||
| 4446 | |||
| 4447 | /** |
||
| 4448 | * Return parent directory path |
||
| 4449 | * |
||
| 4450 | * @param string $path file path |
||
| 4451 | * @return string |
||
| 4452 | * @author Dmitry (dio) Levashov |
||
| 4453 | **/ |
||
| 4454 | abstract protected function _dirname($path); |
||
| 4455 | |||
| 4456 | /** |
||
| 4457 | * Return file name |
||
| 4458 | * |
||
| 4459 | * @param string $path file path |
||
| 4460 | * @return string |
||
| 4461 | * @author Dmitry (dio) Levashov |
||
| 4462 | **/ |
||
| 4463 | abstract protected function _basename($path); |
||
| 4464 | |||
| 4465 | /** |
||
| 4466 | * Join dir name and file name and return full path. |
||
| 4467 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 4468 | * |
||
| 4469 | * @param string $dir dir path |
||
| 4470 | * @param string $name file name |
||
| 4471 | * @return string |
||
| 4472 | * @author Dmitry (dio) Levashov |
||
| 4473 | **/ |
||
| 4474 | abstract protected function _joinPath($dir, $name); |
||
| 4475 | |||
| 4476 | /** |
||
| 4477 | * Return normalized path |
||
| 4478 | * |
||
| 4479 | * @param string $path file path |
||
| 4480 | * @return string |
||
| 4481 | * @author Dmitry (dio) Levashov |
||
| 4482 | **/ |
||
| 4483 | abstract protected function _normpath($path); |
||
| 4484 | |||
| 4485 | /** |
||
| 4486 | * Return file path related to root dir |
||
| 4487 | * |
||
| 4488 | * @param string $path file path |
||
| 4489 | * @return string |
||
| 4490 | * @author Dmitry (dio) Levashov |
||
| 4491 | **/ |
||
| 4492 | abstract protected function _relpath($path); |
||
| 4493 | |||
| 4494 | /** |
||
| 4495 | * Convert path related to root dir into real path |
||
| 4496 | * |
||
| 4497 | * @param string $path rel file path |
||
| 4498 | * @return string |
||
| 4499 | * @author Dmitry (dio) Levashov |
||
| 4500 | **/ |
||
| 4501 | abstract protected function _abspath($path); |
||
| 4502 | |||
| 4503 | /** |
||
| 4504 | * Return fake path started from root dir. |
||
| 4505 | * Required to show path on client side. |
||
| 4506 | * |
||
| 4507 | * @param string $path file path |
||
| 4508 | * @return string |
||
| 4509 | * @author Dmitry (dio) Levashov |
||
| 4510 | **/ |
||
| 4511 | abstract protected function _path($path); |
||
| 4512 | |||
| 4513 | /** |
||
| 4514 | * Return true if $path is children of $parent |
||
| 4515 | * |
||
| 4516 | * @param string $path path to check |
||
| 4517 | * @param string $parent parent path |
||
| 4518 | * @return bool |
||
| 4519 | * @author Dmitry (dio) Levashov |
||
| 4520 | **/ |
||
| 4521 | abstract protected function _inpath($path, $parent); |
||
| 4522 | |||
| 4523 | /** |
||
| 4524 | * Return stat for given path. |
||
| 4525 | * Stat contains following fields: |
||
| 4526 | * - (int) size file size in b. required |
||
| 4527 | * - (int) ts file modification time in unix time. required |
||
| 4528 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 4529 | * - (bool) read read permissions. required |
||
| 4530 | * - (bool) write write permissions. required |
||
| 4531 | * - (bool) locked is object locked. optionally |
||
| 4532 | * - (bool) hidden is object hidden. optionally |
||
| 4533 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 4534 | * - (string) target for symlinks - link target path. optionally |
||
| 4535 | * |
||
| 4536 | * If file does not exists - returns empty array or false. |
||
| 4537 | * |
||
| 4538 | * @param string $path file path |
||
| 4539 | * @return array|false |
||
| 4540 | * @author Dmitry (dio) Levashov |
||
| 4541 | **/ |
||
| 4542 | abstract protected function _stat($path); |
||
| 4543 | |||
| 4544 | |||
| 4545 | /***************** file stat ********************/ |
||
| 4546 | |||
| 4547 | |||
| 4548 | /** |
||
| 4549 | * Return true if path is dir and has at least one childs directory |
||
| 4550 | * |
||
| 4551 | * @param string $path dir path |
||
| 4552 | * @return bool |
||
| 4553 | * @author Dmitry (dio) Levashov |
||
| 4554 | **/ |
||
| 4555 | abstract protected function _subdirs($path); |
||
| 4556 | |||
| 4557 | /** |
||
| 4558 | * Return object width and height |
||
| 4559 | * Ususaly used for images, but can be realize for video etc... |
||
| 4560 | * |
||
| 4561 | * @param string $path file path |
||
| 4562 | * @param string $mime file mime type |
||
| 4563 | * @return string |
||
| 4564 | * @author Dmitry (dio) Levashov |
||
| 4565 | **/ |
||
| 4566 | abstract protected function _dimensions($path, $mime); |
||
| 4567 | |||
| 4568 | /******************** file/dir content *********************/ |
||
| 4569 | |||
| 4570 | /** |
||
| 4571 | * Return files list in directory |
||
| 4572 | * |
||
| 4573 | * @param string $path dir path |
||
| 4574 | * @return array |
||
| 4575 | * @author Dmitry (dio) Levashov |
||
| 4576 | **/ |
||
| 4577 | abstract protected function _scandir($path); |
||
| 4578 | |||
| 4579 | /** |
||
| 4580 | * Open file and return file pointer |
||
| 4581 | * |
||
| 4582 | * @param string $path file path |
||
| 4583 | * @param bool $write open file for writing |
||
| 4584 | * @return resource|false |
||
| 4585 | * @author Dmitry (dio) Levashov |
||
| 4586 | **/ |
||
| 4587 | abstract protected function _fopen($path, $mode="rb"); |
||
| 4588 | |||
| 4589 | /** |
||
| 4590 | * Close opened file |
||
| 4591 | * |
||
| 4592 | * @param resource $fp file pointer |
||
| 4593 | * @param string $path file path |
||
| 4594 | * @return bool |
||
| 4595 | * @author Dmitry (dio) Levashov |
||
| 4596 | **/ |
||
| 4597 | abstract protected function _fclose($fp, $path=''); |
||
| 4598 | |||
| 4599 | /******************** file/dir manipulations *************************/ |
||
| 4600 | |||
| 4601 | /** |
||
| 4602 | * Create dir and return created dir path or false on failed |
||
| 4603 | * |
||
| 4604 | * @param string $path parent dir path |
||
| 4605 | * @param string $name new directory name |
||
| 4606 | * @return string|bool |
||
| 4607 | * @author Dmitry (dio) Levashov |
||
| 4608 | **/ |
||
| 4609 | abstract protected function _mkdir($path, $name); |
||
| 4610 | |||
| 4611 | /** |
||
| 4612 | * Create file and return it's path or false on failed |
||
| 4613 | * |
||
| 4614 | * @param string $path parent dir path |
||
| 4615 | * @param string $name new file name |
||
| 4616 | * @return string|bool |
||
| 4617 | * @author Dmitry (dio) Levashov |
||
| 4618 | **/ |
||
| 4619 | abstract protected function _mkfile($path, $name); |
||
| 4620 | |||
| 4621 | /** |
||
| 4622 | * Create symlink |
||
| 4623 | * |
||
| 4624 | * @param string $source file to link to |
||
| 4625 | * @param string $targetDir folder to create link in |
||
| 4626 | * @param string $name symlink name |
||
| 4627 | * @return bool |
||
| 4628 | * @author Dmitry (dio) Levashov |
||
| 4629 | **/ |
||
| 4630 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 4631 | |||
| 4632 | /** |
||
| 4633 | * Copy file into another file (only inside one volume) |
||
| 4634 | * |
||
| 4635 | * @param string $source source file path |
||
| 4636 | * @param string $target target dir path |
||
| 4637 | * @param string $name file name |
||
| 4638 | * @return bool |
||
| 4639 | * @author Dmitry (dio) Levashov |
||
| 4640 | **/ |
||
| 4641 | abstract protected function _copy($source, $targetDir, $name); |
||
| 4642 | |||
| 4643 | /** |
||
| 4644 | * Move file into another parent dir. |
||
| 4645 | * Return new file path or false. |
||
| 4646 | * |
||
| 4647 | * @param string $source source file path |
||
| 4648 | * @param string $target target dir path |
||
| 4649 | * @param string $name file name |
||
| 4650 | * @return string|bool |
||
| 4651 | * @author Dmitry (dio) Levashov |
||
| 4652 | **/ |
||
| 4653 | abstract protected function _move($source, $targetDir, $name); |
||
| 4654 | |||
| 4655 | /** |
||
| 4656 | * Remove file |
||
| 4657 | * |
||
| 4658 | * @param string $path file path |
||
| 4659 | * @return bool |
||
| 4660 | * @author Dmitry (dio) Levashov |
||
| 4661 | **/ |
||
| 4662 | abstract protected function _unlink($path); |
||
| 4663 | |||
| 4664 | /** |
||
| 4665 | * Remove dir |
||
| 4666 | * |
||
| 4667 | * @param string $path dir path |
||
| 4668 | * @return bool |
||
| 4669 | * @author Dmitry (dio) Levashov |
||
| 4670 | **/ |
||
| 4671 | abstract protected function _rmdir($path); |
||
| 4672 | |||
| 4673 | /** |
||
| 4674 | * Create new file and write into it from file pointer. |
||
| 4675 | * Return new file path or false on error. |
||
| 4676 | * |
||
| 4677 | * @param resource $fp file pointer |
||
| 4678 | * @param string $dir target dir path |
||
| 4679 | * @param string $name file name |
||
| 4680 | * @param array $stat file stat (required by some virtual fs) |
||
| 4681 | * @return bool|string |
||
| 4682 | * @author Dmitry (dio) Levashov |
||
| 4683 | **/ |
||
| 4684 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 4685 | |||
| 4686 | /** |
||
| 4687 | * Get file contents |
||
| 4688 | * |
||
| 4689 | * @param string $path file path |
||
| 4690 | * @return string|false |
||
| 4691 | * @author Dmitry (dio) Levashov |
||
| 4692 | **/ |
||
| 4693 | abstract protected function _getContents($path); |
||
| 4694 | |||
| 4695 | /** |
||
| 4696 | * Write a string to a file |
||
| 4697 | * |
||
| 4698 | * @param string $path file path |
||
| 4699 | * @param string $content new file content |
||
| 4700 | * @return bool |
||
| 4701 | * @author Dmitry (dio) Levashov |
||
| 4702 | **/ |
||
| 4703 | abstract protected function _filePutContents($path, $content); |
||
| 4704 | |||
| 4705 | /** |
||
| 4706 | * Extract files from archive |
||
| 4707 | * |
||
| 4708 | * @param string $path file path |
||
| 4709 | * @param array $arc archiver options |
||
| 4710 | * @return bool |
||
| 4711 | * @author Dmitry (dio) Levashov, |
||
| 4712 | * @author Alexey Sukhotin |
||
| 4713 | **/ |
||
| 4714 | abstract protected function _extract($path, $arc); |
||
| 4715 | |||
| 4716 | /** |
||
| 4717 | * Create archive and return its path |
||
| 4718 | * |
||
| 4719 | * @param string $dir target dir |
||
| 4720 | * @param array $files files names list |
||
| 4721 | * @param string $name archive name |
||
| 4722 | * @param array $arc archiver options |
||
| 4723 | * @return string|bool |
||
| 4724 | * @author Dmitry (dio) Levashov, |
||
| 4725 | * @author Alexey Sukhotin |
||
| 4726 | **/ |
||
| 4727 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 4728 | |||
| 4729 | /** |
||
| 4730 | * Detect available archivers |
||
| 4731 | * |
||
| 4732 | * @return void |
||
| 4733 | * @author Dmitry (dio) Levashov, |
||
| 4734 | * @author Alexey Sukhotin |
||
| 4735 | **/ |
||
| 4736 | abstract protected function _checkArchivers(); |
||
| 4737 | |||
| 4738 | /** |
||
| 4739 | * Change file mode (chmod) |
||
| 4740 | * |
||
| 4741 | * @param string $path file path |
||
| 4742 | * @param string $mode octal string such as '0755' |
||
| 4743 | * @return bool |
||
| 4744 | * @author David Bartle, |
||
| 4745 | **/ |
||
| 4746 | abstract protected function _chmod($path, $mode); |
||
| 4747 | |||
| 4748 | |||
| 4749 | } // END class |
||
| 4750 |
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.