Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like elFinderVolumeDriver often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use elFinderVolumeDriver, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | abstract class elFinderVolumeDriver { |
||
|
|
|||
| 15 | |||
| 16 | /** |
||
| 17 | * Request args |
||
| 18 | * $_POST or $_GET values |
||
| 19 | * |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected $ARGS = array(); |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Driver id |
||
| 26 | * Must be started from letter and contains [a-z0-9] |
||
| 27 | * Used as part of volume id |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | **/ |
||
| 31 | protected $driverId = 'a'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Volume id - used as prefix for files hashes |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | **/ |
||
| 38 | protected $id = ''; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Flag - volume "mounted" and available |
||
| 42 | * |
||
| 43 | * @var bool |
||
| 44 | **/ |
||
| 45 | protected $mounted = false; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Root directory path |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | **/ |
||
| 52 | protected $root = ''; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Root basename | alias |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | **/ |
||
| 59 | protected $rootName = ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Default directory to open |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | **/ |
||
| 66 | protected $startPath = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Base URL |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | **/ |
||
| 73 | protected $URL = ''; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Thumbnails dir path |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | **/ |
||
| 80 | protected $tmbPath = ''; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Is thumbnails dir writable |
||
| 84 | * |
||
| 85 | * @var bool |
||
| 86 | **/ |
||
| 87 | protected $tmbPathWritable = false; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Thumbnails base URL |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | **/ |
||
| 94 | protected $tmbURL = ''; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Thumbnails size in px |
||
| 98 | * |
||
| 99 | * @var int |
||
| 100 | **/ |
||
| 101 | protected $tmbSize = 48; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Image manipulation lib name |
||
| 105 | * auto|imagick|mogtify|gd |
||
| 106 | * |
||
| 107 | * @var string |
||
| 108 | **/ |
||
| 109 | protected $imgLib = 'auto'; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Library to crypt files name |
||
| 113 | * |
||
| 114 | * @var string |
||
| 115 | **/ |
||
| 116 | protected $cryptLib = ''; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Archivers config |
||
| 120 | * |
||
| 121 | * @var array |
||
| 122 | **/ |
||
| 123 | protected $archivers = array( |
||
| 124 | 'create' => array(), |
||
| 125 | 'extract' => array() |
||
| 126 | ); |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Server character encoding |
||
| 130 | * |
||
| 131 | * @var string or null |
||
| 132 | **/ |
||
| 133 | protected $encoding = null; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * How many subdirs levels return for tree |
||
| 137 | * |
||
| 138 | * @var int |
||
| 139 | **/ |
||
| 140 | protected $treeDeep = 1; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Errors from last failed action |
||
| 144 | * |
||
| 145 | * @var array |
||
| 146 | **/ |
||
| 147 | protected $error = array(); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Today 24:00 timestamp |
||
| 151 | * |
||
| 152 | * @var int |
||
| 153 | **/ |
||
| 154 | protected $today = 0; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Yesterday 24:00 timestamp |
||
| 158 | * |
||
| 159 | * @var int |
||
| 160 | **/ |
||
| 161 | protected $yesterday = 0; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Force make dirctory on extract |
||
| 165 | * |
||
| 166 | * @var int |
||
| 167 | **/ |
||
| 168 | protected $extractToNewdir = 'auto'; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Object configuration |
||
| 172 | * |
||
| 173 | * @var array |
||
| 174 | **/ |
||
| 175 | protected $options = array( |
||
| 176 | 'id' => '', |
||
| 177 | // root directory path |
||
| 178 | 'path' => '', |
||
| 179 | // open this path on initial request instead of root path |
||
| 180 | 'startPath' => '', |
||
| 181 | // how many subdirs levels return per request |
||
| 182 | 'treeDeep' => 1, |
||
| 183 | // root url, not set to disable sending URL to client (replacement for old "fileURL" option) |
||
| 184 | 'URL' => '', |
||
| 185 | // directory separator. required by client to show paths correctly |
||
| 186 | 'separator' => DIRECTORY_SEPARATOR, |
||
| 187 | // Server character encoding (default is '': UTF-8) |
||
| 188 | 'encoding' => '', |
||
| 189 | // for convert character encoding (default is '': Not change locale) |
||
| 190 | 'locale' => '', |
||
| 191 | // URL of volume icon (16x16 pixel image file) |
||
| 192 | 'icon' => '', |
||
| 193 | // CSS Class of volume root in tree |
||
| 194 | 'rootCssClass' => '', |
||
| 195 | // library to crypt/uncrypt files names (not implemented) |
||
| 196 | 'cryptLib' => '', |
||
| 197 | // how to detect files mimetypes. (auto/internal/finfo/mime_content_type) |
||
| 198 | 'mimeDetect' => 'auto', |
||
| 199 | // mime.types file path (for mimeDetect==internal) |
||
| 200 | 'mimefile' => '', |
||
| 201 | // mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
| 202 | 'mimeMap' => array( |
||
| 203 | 'md:application/x-genesis-rom' => 'text/x-markdown', |
||
| 204 | 'md:text/plain' => 'text/x-markdown', |
||
| 205 | 'markdown:text/plain' => 'text/x-markdown', |
||
| 206 | 'css:text/x-asm' => 'text/css' |
||
| 207 | ), |
||
| 208 | // directory for thumbnails |
||
| 209 | 'tmbPath' => '.tmb', |
||
| 210 | // mode to create thumbnails dir |
||
| 211 | 'tmbPathMode' => 0777, |
||
| 212 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
| 213 | 'tmbURL' => '', |
||
| 214 | // thumbnails size (px) |
||
| 215 | 'tmbSize' => 48, |
||
| 216 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
| 217 | 'tmbCrop' => true, |
||
| 218 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
| 219 | 'tmbBgColor' => '#ffffff', |
||
| 220 | // image manipulations library |
||
| 221 | 'imgLib' => 'auto', |
||
| 222 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 223 | 'copyOverwrite' => true, |
||
| 224 | // if true - join new and old directories content on paste |
||
| 225 | 'copyJoin' => true, |
||
| 226 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 227 | 'uploadOverwrite' => true, |
||
| 228 | // mimetypes allowed to upload |
||
| 229 | 'uploadAllow' => array(), |
||
| 230 | // mimetypes not allowed to upload |
||
| 231 | 'uploadDeny' => array(), |
||
| 232 | // order to proccess uploadAllow and uploadDeny options |
||
| 233 | 'uploadOrder' => array('deny', 'allow'), |
||
| 234 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
| 235 | 'uploadMaxSize' => 0, |
||
| 236 | // files dates format |
||
| 237 | 'dateFormat' => 'j M Y H:i', |
||
| 238 | // files time format |
||
| 239 | 'timeFormat' => 'H:i', |
||
| 240 | // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders |
||
| 241 | 'checkSubfolders' => true, |
||
| 242 | // allow to copy from this volume to other ones? |
||
| 243 | 'copyFrom' => true, |
||
| 244 | // allow to copy from other volumes to this one? |
||
| 245 | 'copyTo' => true, |
||
| 246 | // list of commands disabled on this root |
||
| 247 | 'disabled' => array(), |
||
| 248 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
| 249 | 'statOwner' => false, |
||
| 250 | // allow exec chmod of read-only files |
||
| 251 | 'allowChmodReadOnly' => false, |
||
| 252 | // regexp or function name to validate new file name |
||
| 253 | 'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it! |
||
| 254 | // function/class method to control files permissions |
||
| 255 | 'accessControl' => null, |
||
| 256 | // some data required by access control |
||
| 257 | 'accessControlData' => null, |
||
| 258 | // default permissions. |
||
| 259 | 'defaults' => array( |
||
| 260 | 'read' => true, |
||
| 261 | 'write' => true, |
||
| 262 | 'locked' => false, |
||
| 263 | 'hidden' => false |
||
| 264 | ), |
||
| 265 | // files attributes |
||
| 266 | 'attributes' => array(), |
||
| 267 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
| 268 | 'archiveMimes' => array(), |
||
| 269 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
| 270 | 'archivers' => array(), |
||
| 271 | // plugin settings |
||
| 272 | 'plugin' => array(), |
||
| 273 | // required to fix bug on macos |
||
| 274 | 'utf8fix' => false, |
||
| 275 | // й ё Й Ё Ø Å |
||
| 276 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
| 277 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
| 278 | ); |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Defaults permissions |
||
| 282 | * |
||
| 283 | * @var array |
||
| 284 | **/ |
||
| 285 | protected $defaults = array( |
||
| 286 | 'read' => true, |
||
| 287 | 'write' => true, |
||
| 288 | 'locked' => false, |
||
| 289 | 'hidden' => false |
||
| 290 | ); |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Access control function/class |
||
| 294 | * |
||
| 295 | * @var mixed |
||
| 296 | **/ |
||
| 297 | protected $attributes = array(); |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Access control function/class |
||
| 301 | * |
||
| 302 | * @var mixed |
||
| 303 | **/ |
||
| 304 | protected $access = null; |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Mime types allowed to upload |
||
| 308 | * |
||
| 309 | * @var array |
||
| 310 | **/ |
||
| 311 | protected $uploadAllow = array(); |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Mime types denied to upload |
||
| 315 | * |
||
| 316 | * @var array |
||
| 317 | **/ |
||
| 318 | protected $uploadDeny = array(); |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Order to validate uploadAllow and uploadDeny |
||
| 322 | * |
||
| 323 | * @var array |
||
| 324 | **/ |
||
| 325 | protected $uploadOrder = array(); |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Maximum allowed upload file size. |
||
| 329 | * Set as number or string with unit - "10M", "500K", "1G" |
||
| 330 | * |
||
| 331 | * @var int|string |
||
| 332 | **/ |
||
| 333 | protected $uploadMaxSize = 0; |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Mimetype detect method |
||
| 337 | * |
||
| 338 | * @var string |
||
| 339 | **/ |
||
| 340 | protected $mimeDetect = 'auto'; |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Flag - mimetypes from externail file was loaded |
||
| 344 | * |
||
| 345 | * @var bool |
||
| 346 | **/ |
||
| 347 | private static $mimetypesLoaded = false; |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Finfo object for mimeDetect == 'finfo' |
||
| 351 | * |
||
| 352 | * @var object |
||
| 353 | **/ |
||
| 354 | protected $finfo = null; |
||
| 355 | |||
| 356 | /** |
||
| 357 | * List of disabled client's commands |
||
| 358 | * |
||
| 359 | * @var array |
||
| 360 | **/ |
||
| 361 | protected $disabled = array(); |
||
| 362 | |||
| 363 | /** |
||
| 364 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
| 365 | * |
||
| 366 | * @var array |
||
| 367 | **/ |
||
| 368 | protected static $mimetypes = array( |
||
| 369 | // applications |
||
| 370 | 'ai' => 'application/postscript', |
||
| 371 | 'eps' => 'application/postscript', |
||
| 372 | 'exe' => 'application/x-executable', |
||
| 373 | 'doc' => 'application/vnd.ms-word', |
||
| 374 | 'xls' => 'application/vnd.ms-excel', |
||
| 375 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 376 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 377 | 'pdf' => 'application/pdf', |
||
| 378 | 'xml' => 'application/xml', |
||
| 379 | 'swf' => 'application/x-shockwave-flash', |
||
| 380 | 'torrent' => 'application/x-bittorrent', |
||
| 381 | 'jar' => 'application/x-jar', |
||
| 382 | // open office (finfo detect as application/zip) |
||
| 383 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
| 384 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
| 385 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
| 386 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
| 387 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
| 388 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
| 389 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
| 390 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
| 391 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
| 392 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
| 393 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
| 394 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
| 395 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
| 396 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
| 397 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
| 398 | // MS office 2007 (finfo detect as application/zip) |
||
| 399 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
| 400 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
| 401 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
| 402 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
| 403 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
| 404 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
| 405 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
| 406 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
| 407 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
| 408 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
| 409 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
| 410 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
| 411 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
| 412 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
| 413 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
| 414 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
| 415 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
| 416 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
| 417 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
| 418 | // archives |
||
| 419 | 'gz' => 'application/x-gzip', |
||
| 420 | 'tgz' => 'application/x-gzip', |
||
| 421 | 'bz' => 'application/x-bzip2', |
||
| 422 | 'bz2' => 'application/x-bzip2', |
||
| 423 | 'tbz' => 'application/x-bzip2', |
||
| 424 | 'xz' => 'application/x-xz', |
||
| 425 | 'zip' => 'application/zip', |
||
| 426 | 'rar' => 'application/x-rar', |
||
| 427 | 'tar' => 'application/x-tar', |
||
| 428 | '7z' => 'application/x-7z-compressed', |
||
| 429 | // texts |
||
| 430 | 'txt' => 'text/plain', |
||
| 431 | 'php' => 'text/x-php', |
||
| 432 | 'html' => 'text/html', |
||
| 433 | 'htm' => 'text/html', |
||
| 434 | 'js' => 'text/javascript', |
||
| 435 | 'css' => 'text/css', |
||
| 436 | 'rtf' => 'text/rtf', |
||
| 437 | 'rtfd' => 'text/rtfd', |
||
| 438 | 'py' => 'text/x-python', |
||
| 439 | 'java' => 'text/x-java-source', |
||
| 440 | 'rb' => 'text/x-ruby', |
||
| 441 | 'sh' => 'text/x-shellscript', |
||
| 442 | 'pl' => 'text/x-perl', |
||
| 443 | 'xml' => 'text/xml', |
||
| 444 | 'sql' => 'text/x-sql', |
||
| 445 | 'c' => 'text/x-csrc', |
||
| 446 | 'h' => 'text/x-chdr', |
||
| 447 | 'cpp' => 'text/x-c++src', |
||
| 448 | 'hh' => 'text/x-c++hdr', |
||
| 449 | 'log' => 'text/plain', |
||
| 450 | 'csv' => 'text/x-comma-separated-values', |
||
| 451 | 'md' => 'text/x-markdown', |
||
| 452 | 'markdown' => 'text/x-markdown', |
||
| 453 | // images |
||
| 454 | 'bmp' => 'image/x-ms-bmp', |
||
| 455 | 'jpg' => 'image/jpeg', |
||
| 456 | 'jpeg' => 'image/jpeg', |
||
| 457 | 'gif' => 'image/gif', |
||
| 458 | 'png' => 'image/png', |
||
| 459 | 'tif' => 'image/tiff', |
||
| 460 | 'tiff' => 'image/tiff', |
||
| 461 | 'tga' => 'image/x-targa', |
||
| 462 | 'psd' => 'image/vnd.adobe.photoshop', |
||
| 463 | 'ai' => 'image/vnd.adobe.photoshop', |
||
| 464 | 'xbm' => 'image/xbm', |
||
| 465 | 'pxm' => 'image/pxm', |
||
| 466 | //audio |
||
| 467 | 'mp3' => 'audio/mpeg', |
||
| 468 | 'mid' => 'audio/midi', |
||
| 469 | 'ogg' => 'audio/ogg', |
||
| 470 | 'oga' => 'audio/ogg', |
||
| 471 | 'm4a' => 'audio/x-m4a', |
||
| 472 | 'wav' => 'audio/wav', |
||
| 473 | 'wma' => 'audio/x-ms-wma', |
||
| 474 | // video |
||
| 475 | 'avi' => 'video/x-msvideo', |
||
| 476 | 'dv' => 'video/x-dv', |
||
| 477 | 'mp4' => 'video/mp4', |
||
| 478 | 'mpeg' => 'video/mpeg', |
||
| 479 | 'mpg' => 'video/mpeg', |
||
| 480 | 'mov' => 'video/quicktime', |
||
| 481 | 'wm' => 'video/x-ms-wmv', |
||
| 482 | 'flv' => 'video/x-flv', |
||
| 483 | 'mkv' => 'video/x-matroska', |
||
| 484 | 'webm' => 'video/webm', |
||
| 485 | 'ogv' => 'video/ogg', |
||
| 486 | 'ogm' => 'video/ogg' |
||
| 487 | ); |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Directory separator - required by client |
||
| 491 | * |
||
| 492 | * @var string |
||
| 493 | **/ |
||
| 494 | protected $separator = DIRECTORY_SEPARATOR; |
||
| 495 | |||
| 496 | /** |
||
| 497 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
| 498 | * |
||
| 499 | * @var string |
||
| 500 | **/ |
||
| 501 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Mimetypes allowed to display |
||
| 505 | * |
||
| 506 | * @var array |
||
| 507 | **/ |
||
| 508 | protected $onlyMimes = array(); |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Store files moved or overwrited files info |
||
| 512 | * |
||
| 513 | * @var array |
||
| 514 | **/ |
||
| 515 | protected $removed = array(); |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Cache storage |
||
| 519 | * |
||
| 520 | * @var array |
||
| 521 | **/ |
||
| 522 | protected $cache = array(); |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Cache by folders |
||
| 526 | * |
||
| 527 | * @var array |
||
| 528 | **/ |
||
| 529 | protected $dirsCache = array(); |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Cache for subdirsCE() |
||
| 533 | * |
||
| 534 | * @var array |
||
| 535 | */ |
||
| 536 | protected $subdirsCache = array(); |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
| 540 | * |
||
| 541 | * @var array |
||
| 542 | */ |
||
| 543 | protected $sessionCache; |
||
| 544 | |||
| 545 | /*********************************************************************/ |
||
| 546 | /* INITIALIZATION */ |
||
| 547 | /*********************************************************************/ |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Prepare driver before mount volume. |
||
| 551 | * Return true if volume is ready. |
||
| 552 | * |
||
| 553 | * @return bool |
||
| 554 | * @author Dmitry (dio) Levashov |
||
| 555 | **/ |
||
| 556 | protected function init() { |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Configure after successfull mount. |
||
| 562 | * By default set thumbnails path and image manipulation library. |
||
| 563 | * |
||
| 564 | * @return void |
||
| 565 | * @author Dmitry (dio) Levashov |
||
| 566 | **/ |
||
| 567 | protected function configure() { |
||
| 608 | |||
| 609 | |||
| 610 | /*********************************************************************/ |
||
| 611 | /* PUBLIC API */ |
||
| 612 | /*********************************************************************/ |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Return driver id. Used as a part of volume id. |
||
| 616 | * |
||
| 617 | * @return string |
||
| 618 | * @author Dmitry (dio) Levashov |
||
| 619 | **/ |
||
| 620 | public function driverId() { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Return volume id |
||
| 626 | * |
||
| 627 | * @return string |
||
| 628 | * @author Dmitry (dio) Levashov |
||
| 629 | **/ |
||
| 630 | public function id() { |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Return debug info for client |
||
| 636 | * |
||
| 637 | * @return array |
||
| 638 | * @author Dmitry (dio) Levashov |
||
| 639 | **/ |
||
| 640 | public function debug() { |
||
| 648 | |||
| 649 | /** |
||
| 650 | * chmod a file or folder |
||
| 651 | * |
||
| 652 | * @param string $hash file or folder hash to chmod |
||
| 653 | * @param string $mode octal string representing new permissions |
||
| 654 | * @return array|false |
||
| 655 | * @author David Bartle |
||
| 656 | **/ |
||
| 657 | public function chmod($hash, $mode) { |
||
| 693 | |||
| 694 | /** |
||
| 695 | * "Mount" volume. |
||
| 696 | * Return true if volume available for read or write, |
||
| 697 | * false - otherwise |
||
| 698 | * |
||
| 699 | * @return bool |
||
| 700 | * @author Dmitry (dio) Levashov |
||
| 701 | * @author Alexey Sukhotin |
||
| 702 | **/ |
||
| 703 | public function mount(array $opts) { |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Some "unmount" stuffs - may be required by virtual fs |
||
| 969 | * |
||
| 970 | * @return void |
||
| 971 | * @author Dmitry (dio) Levashov |
||
| 972 | **/ |
||
| 973 | public function umount() { |
||
| 975 | |||
| 976 | /** |
||
| 977 | * Return error message from last failed action |
||
| 978 | * |
||
| 979 | * @return array |
||
| 980 | * @author Dmitry (dio) Levashov |
||
| 981 | **/ |
||
| 982 | public function error() { |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
| 988 | * |
||
| 989 | * @return array |
||
| 990 | * @author Naoki Sawada |
||
| 991 | */ |
||
| 992 | public function getMimeTable() { |
||
| 995 | |||
| 996 | /** |
||
| 997 | * Set mimetypes allowed to display to client |
||
| 998 | * |
||
| 999 | * @param array $mimes |
||
| 1000 | * @return void |
||
| 1001 | * @author Dmitry (dio) Levashov |
||
| 1002 | **/ |
||
| 1003 | public function setMimesFilter($mimes) { |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Return root folder hash |
||
| 1011 | * |
||
| 1012 | * @return string |
||
| 1013 | * @author Dmitry (dio) Levashov |
||
| 1014 | **/ |
||
| 1015 | public function root() { |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Return target path hash |
||
| 1021 | * |
||
| 1022 | * @param string $path |
||
| 1023 | * @param string $name |
||
| 1024 | * @author Naoki Sawada |
||
| 1025 | */ |
||
| 1026 | public function getHash($path, $name = '') { |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * Return root or startPath hash |
||
| 1035 | * |
||
| 1036 | * @return string |
||
| 1037 | * @author Dmitry (dio) Levashov |
||
| 1038 | **/ |
||
| 1039 | public function defaultPath() { |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Return volume options required by client: |
||
| 1045 | * |
||
| 1046 | * @return array |
||
| 1047 | * @author Dmitry (dio) Levashov |
||
| 1048 | **/ |
||
| 1049 | public function options($hash) { |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Get plugin values of this options |
||
| 1076 | * |
||
| 1077 | * @param string $name Plugin name |
||
| 1078 | * @return NULL|array Plugin values |
||
| 1079 | * @author Naoki Sawada |
||
| 1080 | */ |
||
| 1081 | public function getOptionsPlugin($name = '') { |
||
| 1088 | |||
| 1089 | /** |
||
| 1090 | * Return true if command disabled in options |
||
| 1091 | * |
||
| 1092 | * @param string $cmd command name |
||
| 1093 | * @return bool |
||
| 1094 | * @author Dmitry (dio) Levashov |
||
| 1095 | **/ |
||
| 1096 | public function commandDisabled($cmd) { |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * Return true if mime is required mimes list |
||
| 1102 | * |
||
| 1103 | * @param string $mime mime type to check |
||
| 1104 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1105 | * @param bool|null $empty what to return on empty list |
||
| 1106 | * @return bool|null |
||
| 1107 | * @author Dmitry (dio) Levashov |
||
| 1108 | * @author Troex Nevelin |
||
| 1109 | **/ |
||
| 1110 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
| 1121 | |||
| 1122 | /** |
||
| 1123 | * Return true if voume is readable. |
||
| 1124 | * |
||
| 1125 | * @return bool |
||
| 1126 | * @author Dmitry (dio) Levashov |
||
| 1127 | **/ |
||
| 1128 | public function isReadable() { |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Return true if copy from this volume allowed |
||
| 1135 | * |
||
| 1136 | * @return bool |
||
| 1137 | * @author Dmitry (dio) Levashov |
||
| 1138 | **/ |
||
| 1139 | public function copyFromAllowed() { |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * Return file path related to root with convert encoging |
||
| 1145 | * |
||
| 1146 | * @param string $hash file hash |
||
| 1147 | * @return string |
||
| 1148 | * @author Dmitry (dio) Levashov |
||
| 1149 | **/ |
||
| 1150 | public function path($hash) { |
||
| 1153 | |||
| 1154 | /** |
||
| 1155 | * Return file real path if file exists |
||
| 1156 | * |
||
| 1157 | * @param string $hash file hash |
||
| 1158 | * @return string |
||
| 1159 | * @author Dmitry (dio) Levashov |
||
| 1160 | **/ |
||
| 1161 | public function realpath($hash) { |
||
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Return list of moved/overwrited files |
||
| 1168 | * |
||
| 1169 | * @return array |
||
| 1170 | * @author Dmitry (dio) Levashov |
||
| 1171 | **/ |
||
| 1172 | public function removed() { |
||
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Clean removed files list |
||
| 1178 | * |
||
| 1179 | * @return void |
||
| 1180 | * @author Dmitry (dio) Levashov |
||
| 1181 | **/ |
||
| 1182 | public function resetRemoved() { |
||
| 1185 | |||
| 1186 | /** |
||
| 1187 | * Return file/dir hash or first founded child hash with required attr == $val |
||
| 1188 | * |
||
| 1189 | * @param string $hash file hash |
||
| 1190 | * @param string $attr attribute name |
||
| 1191 | * @param bool $val attribute value |
||
| 1192 | * @return string|false |
||
| 1193 | * @author Dmitry (dio) Levashov |
||
| 1194 | **/ |
||
| 1195 | public function closest($hash, $attr, $val) { |
||
| 1198 | |||
| 1199 | /** |
||
| 1200 | * Return file info or false on error |
||
| 1201 | * |
||
| 1202 | * @param string $hash file hash |
||
| 1203 | * @param bool $realpath add realpath field to file info |
||
| 1204 | * @return array|false |
||
| 1205 | * @author Dmitry (dio) Levashov |
||
| 1206 | **/ |
||
| 1207 | public function file($hash) { |
||
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Return folder info |
||
| 1222 | * |
||
| 1223 | * @param string $hash folder hash |
||
| 1224 | * @param bool $hidden return hidden file info |
||
| 1225 | * @return array|false |
||
| 1226 | * @author Dmitry (dio) Levashov |
||
| 1227 | **/ |
||
| 1228 | public function dir($hash, $resolveLink=false) { |
||
| 1241 | |||
| 1242 | /** |
||
| 1243 | * Return directory content or false on error |
||
| 1244 | * |
||
| 1245 | * @param string $hash file hash |
||
| 1246 | * @return array|false |
||
| 1247 | * @author Dmitry (dio) Levashov |
||
| 1248 | **/ |
||
| 1249 | public function scandir($hash) { |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Return dir files names list |
||
| 1261 | * |
||
| 1262 | * @param string $hash file hash |
||
| 1263 | * @return array |
||
| 1264 | * @author Dmitry (dio) Levashov |
||
| 1265 | **/ |
||
| 1266 | public function ls($hash) { |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Return subfolders for required folder or false on error |
||
| 1285 | * |
||
| 1286 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1287 | * @param int $deep subdir deep |
||
| 1288 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1289 | * @return array|false |
||
| 1290 | * @author Dmitry (dio) Levashov |
||
| 1291 | **/ |
||
| 1292 | public function tree($hash='', $deep=0, $exclude='') { |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Return part of dirs tree from required dir up to root dir |
||
| 1306 | * |
||
| 1307 | * @param string $hash directory hash |
||
| 1308 | * @param bool|null $lineal only lineal parents |
||
| 1309 | * @return array |
||
| 1310 | * @author Dmitry (dio) Levashov |
||
| 1311 | **/ |
||
| 1312 | public function parents($hash, $lineal = false) { |
||
| 1339 | |||
| 1340 | /** |
||
| 1341 | * Create thumbnail for required file and return its name of false on failed |
||
| 1342 | * |
||
| 1343 | * @return string|false |
||
| 1344 | * @author Dmitry (dio) Levashov |
||
| 1345 | **/ |
||
| 1346 | public function tmb($hash) { |
||
| 1355 | |||
| 1356 | /** |
||
| 1357 | * Return file size / total directory size |
||
| 1358 | * |
||
| 1359 | * @param string file hash |
||
| 1360 | * @return int |
||
| 1361 | * @author Dmitry (dio) Levashov |
||
| 1362 | **/ |
||
| 1363 | public function size($hash) { |
||
| 1366 | |||
| 1367 | /** |
||
| 1368 | * Open file for reading and return file pointer |
||
| 1369 | * |
||
| 1370 | * @param string file hash |
||
| 1371 | * @return Resource |
||
| 1372 | * @author Dmitry (dio) Levashov |
||
| 1373 | **/ |
||
| 1374 | public function open($hash) { |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Close file pointer |
||
| 1385 | * |
||
| 1386 | * @param Resource $fp file pointer |
||
| 1387 | * @param string $hash file hash |
||
| 1388 | * @return void |
||
| 1389 | * @author Dmitry (dio) Levashov |
||
| 1390 | **/ |
||
| 1391 | public function close($fp, $hash) { |
||
| 1394 | |||
| 1395 | /** |
||
| 1396 | * Create directory and return dir info |
||
| 1397 | * |
||
| 1398 | * @param string $dsthash destination directory hash |
||
| 1399 | * @param string $name directory name |
||
| 1400 | * @return array|false |
||
| 1401 | * @author Dmitry (dio) Levashov |
||
| 1402 | **/ |
||
| 1403 | public function mkdir($dsthash, $name) { |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * Create empty file and return its info |
||
| 1433 | * |
||
| 1434 | * @param string $dst destination directory |
||
| 1435 | * @param string $name file name |
||
| 1436 | * @return array|false |
||
| 1437 | * @author Dmitry (dio) Levashov |
||
| 1438 | **/ |
||
| 1439 | public function mkfile($dst, $name) { |
||
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Rename file and return file info |
||
| 1468 | * |
||
| 1469 | * @param string $hash file hash |
||
| 1470 | * @param string $name new file name |
||
| 1471 | * @return array|false |
||
| 1472 | * @author Dmitry (dio) Levashov |
||
| 1473 | **/ |
||
| 1474 | public function rename($hash, $name) { |
||
| 1520 | |||
| 1521 | /** |
||
| 1522 | * Create file copy with suffix "copy number" and return its info |
||
| 1523 | * |
||
| 1524 | * @param string $hash file hash |
||
| 1525 | * @param string $suffix suffix to add to file name |
||
| 1526 | * @return array|false |
||
| 1527 | * @author Dmitry (dio) Levashov |
||
| 1528 | **/ |
||
| 1529 | public function duplicate($hash, $suffix='copy') { |
||
| 1550 | |||
| 1551 | /** |
||
| 1552 | * Save uploaded file. |
||
| 1553 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
| 1554 | * |
||
| 1555 | * @param Resource $fp file pointer |
||
| 1556 | * @param string $dst destination folder hash |
||
| 1557 | * @param string $src file name |
||
| 1558 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 1559 | * @return array|false |
||
| 1560 | * @author Dmitry (dio) Levashov |
||
| 1561 | **/ |
||
| 1562 | public function upload($fp, $dst, $name, $tmpname) { |
||
| 1638 | |||
| 1639 | /** |
||
| 1640 | * Paste files |
||
| 1641 | * |
||
| 1642 | * @param Object $volume source volume |
||
| 1643 | * @param string $source file hash |
||
| 1644 | * @param string $dst destination dir hash |
||
| 1645 | * @param bool $rmSrc remove source after copy? |
||
| 1646 | * @return array|false |
||
| 1647 | * @author Dmitry (dio) Levashov |
||
| 1648 | **/ |
||
| 1649 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
| 1737 | |||
| 1738 | /** |
||
| 1739 | * Return file contents |
||
| 1740 | * |
||
| 1741 | * @param string $hash file hash |
||
| 1742 | * @return string|false |
||
| 1743 | * @author Dmitry (dio) Levashov |
||
| 1744 | **/ |
||
| 1745 | public function getContents($hash) { |
||
| 1762 | |||
| 1763 | /** |
||
| 1764 | * Put content in text file and return file info. |
||
| 1765 | * |
||
| 1766 | * @param string $hash file hash |
||
| 1767 | * @param string $content new file content |
||
| 1768 | * @return array |
||
| 1769 | * @author Dmitry (dio) Levashov |
||
| 1770 | **/ |
||
| 1771 | public function putContents($hash, $content) { |
||
| 1806 | |||
| 1807 | /** |
||
| 1808 | * Extract files from archive |
||
| 1809 | * |
||
| 1810 | * @param string $hash archive hash |
||
| 1811 | * @return array|bool |
||
| 1812 | * @author Dmitry (dio) Levashov, |
||
| 1813 | * @author Alexey Sukhotin |
||
| 1814 | **/ |
||
| 1815 | public function extract($hash, $makedir = null) { |
||
| 1854 | |||
| 1855 | /** |
||
| 1856 | * Add files to archive |
||
| 1857 | * |
||
| 1858 | * @return void |
||
| 1859 | **/ |
||
| 1860 | public function archive($hashes, $mime, $name = '') { |
||
| 1904 | |||
| 1905 | /** |
||
| 1906 | * Resize image |
||
| 1907 | * |
||
| 1908 | * @param string $hash image file |
||
| 1909 | * @param int $width new width |
||
| 1910 | * @param int $height new height |
||
| 1911 | * @param int $x X start poistion for crop |
||
| 1912 | * @param int $y Y start poistion for crop |
||
| 1913 | * @param string $mode action how to mainpulate image |
||
| 1914 | * @return array|false |
||
| 1915 | * @author Dmitry (dio) Levashov |
||
| 1916 | * @author Alexey Sukhotin |
||
| 1917 | * @author nao-pon |
||
| 1918 | * @author Troex Nevelin |
||
| 1919 | **/ |
||
| 1920 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0) { |
||
| 2007 | |||
| 2008 | /** |
||
| 2009 | * Remove file/dir |
||
| 2010 | * |
||
| 2011 | * @param string $hash file hash |
||
| 2012 | * @return bool |
||
| 2013 | * @author Dmitry (dio) Levashov |
||
| 2014 | **/ |
||
| 2015 | public function rm($hash) { |
||
| 2020 | |||
| 2021 | /** |
||
| 2022 | * Search files |
||
| 2023 | * |
||
| 2024 | * @param string $q search string |
||
| 2025 | * @param array $mimes |
||
| 2026 | * @return array |
||
| 2027 | * @author Dmitry (dio) Levashov |
||
| 2028 | **/ |
||
| 2029 | public function search($q, $mimes, $hash = null) { |
||
| 2048 | |||
| 2049 | /** |
||
| 2050 | * Return image dimensions |
||
| 2051 | * |
||
| 2052 | * @param string $hash file hash |
||
| 2053 | * @return array |
||
| 2054 | * @author Dmitry (dio) Levashov |
||
| 2055 | **/ |
||
| 2056 | public function dimensions($hash) { |
||
| 2063 | |||
| 2064 | /** |
||
| 2065 | * Return content URL (for netmout volume driver) |
||
| 2066 | * If file.url == 1 requests from JavaScript client with XHR |
||
| 2067 | * |
||
| 2068 | * @param string $hash file hash |
||
| 2069 | * @param array $options options array |
||
| 2070 | * @return boolean|string |
||
| 2071 | * @author Naoki Sawada |
||
| 2072 | */ |
||
| 2073 | public function getContentUrl($hash, $options = array()) { |
||
| 2079 | |||
| 2080 | /** |
||
| 2081 | * Return temp path |
||
| 2082 | * |
||
| 2083 | * @return string |
||
| 2084 | * @author Naoki Sawada |
||
| 2085 | */ |
||
| 2086 | public function getTempPath() { |
||
| 2099 | |||
| 2100 | /** |
||
| 2101 | * (Make &) Get upload taget dirctory hash |
||
| 2102 | * |
||
| 2103 | * @param string $baseTargetHash |
||
| 2104 | * @param string $path |
||
| 2105 | * @param array $result |
||
| 2106 | * @return boolean|string |
||
| 2107 | * @author Naoki Sawada |
||
| 2108 | */ |
||
| 2109 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
| 2136 | |||
| 2137 | /** |
||
| 2138 | * Return this uploadMaxSize value |
||
| 2139 | * |
||
| 2140 | * @return integer |
||
| 2141 | * @author Naoki Sawada |
||
| 2142 | */ |
||
| 2143 | public function getUploadMaxSize() { |
||
| 2146 | |||
| 2147 | /** |
||
| 2148 | * Save error message |
||
| 2149 | * |
||
| 2150 | * @param array error |
||
| 2151 | * @return false |
||
| 2152 | * @author Dmitry(dio) Levashov |
||
| 2153 | **/ |
||
| 2154 | protected function setError($error) { |
||
| 2169 | |||
| 2170 | /*********************************************************************/ |
||
| 2171 | /* FS API */ |
||
| 2172 | /*********************************************************************/ |
||
| 2173 | |||
| 2174 | /***************** server encoding support *******************/ |
||
| 2175 | |||
| 2176 | /** |
||
| 2177 | * Return parent directory path (with convert encording) |
||
| 2178 | * |
||
| 2179 | * @param string $path file path |
||
| 2180 | * @return string |
||
| 2181 | * @author Naoki Sawada |
||
| 2182 | **/ |
||
| 2183 | protected function dirnameCE($path) { |
||
| 2186 | |||
| 2187 | /** |
||
| 2188 | * Return file name (with convert encording) |
||
| 2189 | * |
||
| 2190 | * @param string $path file path |
||
| 2191 | * @return string |
||
| 2192 | * @author Naoki Sawada |
||
| 2193 | **/ |
||
| 2194 | protected function basenameCE($path) { |
||
| 2197 | |||
| 2198 | /** |
||
| 2199 | * Join dir name and file name and return full path. (with convert encording) |
||
| 2200 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 2201 | * |
||
| 2202 | * @param string $dir dir path |
||
| 2203 | * @param string $name file name |
||
| 2204 | * @return string |
||
| 2205 | * @author Naoki Sawada |
||
| 2206 | **/ |
||
| 2207 | protected function joinPathCE($dir, $name) { |
||
| 2210 | |||
| 2211 | /** |
||
| 2212 | * Return normalized path (with convert encording) |
||
| 2213 | * |
||
| 2214 | * @param string $path file path |
||
| 2215 | * @return string |
||
| 2216 | * @author Naoki Sawada |
||
| 2217 | **/ |
||
| 2218 | protected function normpathCE($path) { |
||
| 2221 | |||
| 2222 | /** |
||
| 2223 | * Return file path related to root dir (with convert encording) |
||
| 2224 | * |
||
| 2225 | * @param string $path file path |
||
| 2226 | * @return string |
||
| 2227 | * @author Naoki Sawada |
||
| 2228 | **/ |
||
| 2229 | protected function relpathCE($path) { |
||
| 2232 | |||
| 2233 | /** |
||
| 2234 | * Convert path related to root dir into real path (with convert encording) |
||
| 2235 | * |
||
| 2236 | * @param string $path rel file path |
||
| 2237 | * @return string |
||
| 2238 | * @author Naoki Sawada |
||
| 2239 | **/ |
||
| 2240 | protected function abspathCE($path) { |
||
| 2243 | |||
| 2244 | /** |
||
| 2245 | * Return true if $path is children of $parent (with convert encording) |
||
| 2246 | * |
||
| 2247 | * @param string $path path to check |
||
| 2248 | * @param string $parent parent path |
||
| 2249 | * @return bool |
||
| 2250 | * @author Naoki Sawada |
||
| 2251 | **/ |
||
| 2252 | protected function inpathCE($path, $parent) { |
||
| 2255 | |||
| 2256 | /** |
||
| 2257 | * Open file and return file pointer (with convert encording) |
||
| 2258 | * |
||
| 2259 | * @param string $path file path |
||
| 2260 | * @param bool $write open file for writing |
||
| 2261 | * @return resource|false |
||
| 2262 | * @author Naoki Sawada |
||
| 2263 | **/ |
||
| 2264 | protected function fopenCE($path, $mode='rb') { |
||
| 2267 | |||
| 2268 | /** |
||
| 2269 | * Close opened file (with convert encording) |
||
| 2270 | * |
||
| 2271 | * @param resource $fp file pointer |
||
| 2272 | * @param string $path file path |
||
| 2273 | * @return bool |
||
| 2274 | * @author Naoki Sawada |
||
| 2275 | **/ |
||
| 2276 | protected function fcloseCE($fp, $path='') { |
||
| 2279 | |||
| 2280 | /** |
||
| 2281 | * Create new file and write into it from file pointer. (with convert encording) |
||
| 2282 | * Return new file path or false on error. |
||
| 2283 | * |
||
| 2284 | * @param resource $fp file pointer |
||
| 2285 | * @param string $dir target dir path |
||
| 2286 | * @param string $name file name |
||
| 2287 | * @param array $stat file stat (required by some virtual fs) |
||
| 2288 | * @return bool|string |
||
| 2289 | * @author Naoki Sawada |
||
| 2290 | **/ |
||
| 2291 | protected function saveCE($fp, $dir, $name, $stat) { |
||
| 2294 | |||
| 2295 | /** |
||
| 2296 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
| 2297 | * |
||
| 2298 | * @param string $path dir path |
||
| 2299 | * @return bool |
||
| 2300 | * @author Naoki Sawada |
||
| 2301 | **/ |
||
| 2302 | protected function subdirsCE($path) { |
||
| 2308 | |||
| 2309 | /** |
||
| 2310 | * Return files list in directory (with convert encording) |
||
| 2311 | * |
||
| 2312 | * @param string $path dir path |
||
| 2313 | * @return array |
||
| 2314 | * @author Naoki Sawada |
||
| 2315 | **/ |
||
| 2316 | protected function scandirCE($path) { |
||
| 2319 | |||
| 2320 | /** |
||
| 2321 | * Create symlink (with convert encording) |
||
| 2322 | * |
||
| 2323 | * @param string $source file to link to |
||
| 2324 | * @param string $targetDir folder to create link in |
||
| 2325 | * @param string $name symlink name |
||
| 2326 | * @return bool |
||
| 2327 | * @author Naoki Sawada |
||
| 2328 | **/ |
||
| 2329 | protected function symlinkCE($source, $targetDir, $name) { |
||
| 2332 | |||
| 2333 | /***************** paths *******************/ |
||
| 2334 | |||
| 2335 | /** |
||
| 2336 | * Encode path into hash |
||
| 2337 | * |
||
| 2338 | * @param string file path |
||
| 2339 | * @return string |
||
| 2340 | * @author Dmitry (dio) Levashov |
||
| 2341 | * @author Troex Nevelin |
||
| 2342 | **/ |
||
| 2343 | protected function encode($path) { |
||
| 2364 | |||
| 2365 | /** |
||
| 2366 | * Decode path from hash |
||
| 2367 | * |
||
| 2368 | * @param string file hash |
||
| 2369 | * @return string |
||
| 2370 | * @author Dmitry (dio) Levashov |
||
| 2371 | * @author Troex Nevelin |
||
| 2372 | **/ |
||
| 2373 | protected function decode($hash) { |
||
| 2385 | |||
| 2386 | /** |
||
| 2387 | * Return crypted path |
||
| 2388 | * Not implemented |
||
| 2389 | * |
||
| 2390 | * @param string path |
||
| 2391 | * @return mixed |
||
| 2392 | * @author Dmitry (dio) Levashov |
||
| 2393 | **/ |
||
| 2394 | protected function crypt($path) { |
||
| 2397 | |||
| 2398 | /** |
||
| 2399 | * Return uncrypted path |
||
| 2400 | * Not implemented |
||
| 2401 | * |
||
| 2402 | * @param mixed hash |
||
| 2403 | * @return mixed |
||
| 2404 | * @author Dmitry (dio) Levashov |
||
| 2405 | **/ |
||
| 2406 | protected function uncrypt($hash) { |
||
| 2409 | |||
| 2410 | /** |
||
| 2411 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
| 2412 | * |
||
| 2413 | * @param string $name file name |
||
| 2414 | * @return bool |
||
| 2415 | * @author Dmitry (dio) Levashov |
||
| 2416 | **/ |
||
| 2417 | protected function nameAccepted($name) { |
||
| 2429 | |||
| 2430 | /** |
||
| 2431 | * Return new unique name based on file name and suffix |
||
| 2432 | * |
||
| 2433 | * @param string $path file path |
||
| 2434 | * @param string $suffix suffix append to name |
||
| 2435 | * @return string |
||
| 2436 | * @author Dmitry (dio) Levashov |
||
| 2437 | **/ |
||
| 2438 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum=true) { |
||
| 2466 | |||
| 2467 | /** |
||
| 2468 | * Converts character encoding from UTF-8 to server's one |
||
| 2469 | * |
||
| 2470 | * @param mixed $var target string or array var |
||
| 2471 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 2472 | * @param string $unknown replaces character for unknown |
||
| 2473 | * @return mixed |
||
| 2474 | * @author Naoki Sawada |
||
| 2475 | */ |
||
| 2476 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
| 2479 | |||
| 2480 | /** |
||
| 2481 | * Converts character encoding from server's one to UTF-8 |
||
| 2482 | * |
||
| 2483 | * @param mixed $var target string or array var |
||
| 2484 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 2485 | * @param string $unknown replaces character for unknown |
||
| 2486 | * @return mixed |
||
| 2487 | * @author Naoki Sawada |
||
| 2488 | */ |
||
| 2489 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
| 2492 | |||
| 2493 | /** |
||
| 2494 | * Converts character encoding (base function) |
||
| 2495 | * |
||
| 2496 | * @param mixed $var target string or array var |
||
| 2497 | * @param string $from from character encoding |
||
| 2498 | * @param string $to to character encoding |
||
| 2499 | * @param string $locale local locale |
||
| 2500 | * @param string $unknown replaces character for unknown |
||
| 2501 | * @return mixed |
||
| 2502 | */ |
||
| 2503 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
| 2532 | |||
| 2533 | /*********************** util mainly for inheritance class *********************/ |
||
| 2534 | |||
| 2535 | /** |
||
| 2536 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 2537 | * When needing the unique file to a path, give $path to parameter. |
||
| 2538 | * |
||
| 2539 | * @param string $path for get unique file to a path |
||
| 2540 | * @return string|false |
||
| 2541 | * @author Naoki Sawada |
||
| 2542 | */ |
||
| 2543 | protected function getTempFile($path = '') { |
||
| 2569 | |||
| 2570 | /** |
||
| 2571 | * File path of local server side work file path |
||
| 2572 | * |
||
| 2573 | * @param string $path path need convert encoding to server encoding |
||
| 2574 | * @return string |
||
| 2575 | * @author Naoki Sawada |
||
| 2576 | */ |
||
| 2577 | protected function getWorkFile($path) { |
||
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Get image size array with `dimensions` |
||
| 2595 | * |
||
| 2596 | * @param string $path path need convert encoding to server encoding |
||
| 2597 | * @param string $mime file mime type |
||
| 2598 | * @return array|false |
||
| 2599 | */ |
||
| 2600 | public function getImageSize($path, $mime = '') { |
||
| 2612 | |||
| 2613 | /** |
||
| 2614 | * Delete dirctory trees |
||
| 2615 | * |
||
| 2616 | * @param string $localpath path need convert encoding to server encoding |
||
| 2617 | * @return boolean |
||
| 2618 | * @author Naoki Sawada |
||
| 2619 | */ |
||
| 2620 | protected function delTree($localpath) { |
||
| 2629 | |||
| 2630 | /*********************** file stat *********************/ |
||
| 2631 | |||
| 2632 | /** |
||
| 2633 | * Check file attribute |
||
| 2634 | * |
||
| 2635 | * @param string $path file path |
||
| 2636 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 2637 | * @param bool $val attribute value returned by file system |
||
| 2638 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 2639 | * @return bool |
||
| 2640 | * @author Dmitry (dio) Levashov |
||
| 2641 | **/ |
||
| 2642 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
| 2676 | |||
| 2677 | /** |
||
| 2678 | * Return true if file with given name can be created in given folder. |
||
| 2679 | * |
||
| 2680 | * @param string $dir parent dir path |
||
| 2681 | * @param string $name new file name |
||
| 2682 | * @return bool |
||
| 2683 | * @author Dmitry (dio) Levashov |
||
| 2684 | **/ |
||
| 2685 | protected function allowCreate($dir, $name, $isDir = null) { |
||
| 2708 | |||
| 2709 | /** |
||
| 2710 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 2711 | * |
||
| 2712 | * @param string $mime |
||
| 2713 | * @return boolean |
||
| 2714 | */ |
||
| 2715 | protected function allowPutMime($mime) { |
||
| 2733 | |||
| 2734 | /** |
||
| 2735 | * Return fileinfo |
||
| 2736 | * |
||
| 2737 | * @param string $path file cache |
||
| 2738 | * @return array |
||
| 2739 | * @author Dmitry (dio) Levashov |
||
| 2740 | **/ |
||
| 2741 | protected function stat($path) { |
||
| 2766 | |||
| 2767 | /** |
||
| 2768 | * Put file stat in cache and return it |
||
| 2769 | * |
||
| 2770 | * @param string $path file path |
||
| 2771 | * @param array $stat file stat |
||
| 2772 | * @return array |
||
| 2773 | * @author Dmitry (dio) Levashov |
||
| 2774 | **/ |
||
| 2775 | protected function updateCache($path, $stat) { |
||
| 2914 | |||
| 2915 | /** |
||
| 2916 | * Get stat for folder content and put in cache |
||
| 2917 | * |
||
| 2918 | * @param string $path |
||
| 2919 | * @return void |
||
| 2920 | * @author Dmitry (dio) Levashov |
||
| 2921 | **/ |
||
| 2922 | protected function cacheDir($path) { |
||
| 2935 | |||
| 2936 | /** |
||
| 2937 | * Clean cache |
||
| 2938 | * |
||
| 2939 | * @return void |
||
| 2940 | * @author Dmitry (dio) Levashov |
||
| 2941 | **/ |
||
| 2942 | protected function clearcache() { |
||
| 2945 | |||
| 2946 | /** |
||
| 2947 | * Return file mimetype |
||
| 2948 | * |
||
| 2949 | * @param string $path file path |
||
| 2950 | * @return string |
||
| 2951 | * @author Dmitry (dio) Levashov |
||
| 2952 | **/ |
||
| 2953 | protected function mimetype($path, $name = '') { |
||
| 2998 | |||
| 2999 | /** |
||
| 3000 | * Detect file mimetype using "internal" method |
||
| 3001 | * |
||
| 3002 | * @param string $path file path |
||
| 3003 | * @return string |
||
| 3004 | * @author Dmitry (dio) Levashov |
||
| 3005 | **/ |
||
| 3006 | static protected function mimetypeInternalDetect($path) { |
||
| 3012 | |||
| 3013 | /** |
||
| 3014 | * Return file/total directory size |
||
| 3015 | * |
||
| 3016 | * @param string $path file path |
||
| 3017 | * @return int |
||
| 3018 | * @author Dmitry (dio) Levashov |
||
| 3019 | **/ |
||
| 3020 | protected function countSize($path) { |
||
| 3045 | |||
| 3046 | /** |
||
| 3047 | * Return true if all mimes is directory or files |
||
| 3048 | * |
||
| 3049 | * @param string $mime1 mimetype |
||
| 3050 | * @param string $mime2 mimetype |
||
| 3051 | * @return bool |
||
| 3052 | * @author Dmitry (dio) Levashov |
||
| 3053 | **/ |
||
| 3054 | protected function isSameType($mime1, $mime2) { |
||
| 3057 | |||
| 3058 | /** |
||
| 3059 | * If file has required attr == $val - return file path, |
||
| 3060 | * If dir has child with has required attr == $val - return child path |
||
| 3061 | * |
||
| 3062 | * @param string $path file path |
||
| 3063 | * @param string $attr attribute name |
||
| 3064 | * @param bool $val attribute value |
||
| 3065 | * @return string|false |
||
| 3066 | * @author Dmitry (dio) Levashov |
||
| 3067 | **/ |
||
| 3068 | protected function closestByAttr($path, $attr, $val) { |
||
| 3085 | |||
| 3086 | /** |
||
| 3087 | * Return first found children with required attr == $val |
||
| 3088 | * |
||
| 3089 | * @param string $path file path |
||
| 3090 | * @param string $attr attribute name |
||
| 3091 | * @param bool $val attribute value |
||
| 3092 | * @return string|false |
||
| 3093 | * @author Dmitry (dio) Levashov |
||
| 3094 | **/ |
||
| 3095 | protected function childsByAttr($path, $attr, $val) { |
||
| 3103 | |||
| 3104 | /***************** get content *******************/ |
||
| 3105 | |||
| 3106 | /** |
||
| 3107 | * Return required dir's files info. |
||
| 3108 | * If onlyMimes is set - return only dirs and files of required mimes |
||
| 3109 | * |
||
| 3110 | * @param string $path dir path |
||
| 3111 | * @return array |
||
| 3112 | * @author Dmitry (dio) Levashov |
||
| 3113 | **/ |
||
| 3114 | protected function getScandir($path) { |
||
| 3127 | |||
| 3128 | |||
| 3129 | /** |
||
| 3130 | * Return subdirs tree |
||
| 3131 | * |
||
| 3132 | * @param string $path parent dir path |
||
| 3133 | * @param int $deep tree deep |
||
| 3134 | * @return array |
||
| 3135 | * @author Dmitry (dio) Levashov |
||
| 3136 | **/ |
||
| 3137 | protected function gettree($path, $deep, $exclude='') { |
||
| 3155 | |||
| 3156 | /** |
||
| 3157 | * Recursive files search |
||
| 3158 | * |
||
| 3159 | * @param string $path dir path |
||
| 3160 | * @param string $q search string |
||
| 3161 | * @param array $mimes |
||
| 3162 | * @return array |
||
| 3163 | * @author Dmitry (dio) Levashov |
||
| 3164 | **/ |
||
| 3165 | protected function doSearch($path, $q, $mimes) { |
||
| 3201 | |||
| 3202 | /********************** manuipulations ******************/ |
||
| 3203 | |||
| 3204 | /** |
||
| 3205 | * Copy file/recursive copy dir only in current volume. |
||
| 3206 | * Return new file path or false. |
||
| 3207 | * |
||
| 3208 | * @param string $src source path |
||
| 3209 | * @param string $dst destination dir path |
||
| 3210 | * @param string $name new file name (optionaly) |
||
| 3211 | * @return string|false |
||
| 3212 | * @author Dmitry (dio) Levashov |
||
| 3213 | **/ |
||
| 3214 | protected function copy($src, $dst, $name) { |
||
| 3256 | |||
| 3257 | /** |
||
| 3258 | * Move file |
||
| 3259 | * Return new file path or false. |
||
| 3260 | * |
||
| 3261 | * @param string $src source path |
||
| 3262 | * @param string $dst destination dir path |
||
| 3263 | * @param string $name new file name |
||
| 3264 | * @return string|false |
||
| 3265 | * @author Dmitry (dio) Levashov |
||
| 3266 | **/ |
||
| 3267 | protected function move($src, $dst, $name) { |
||
| 3281 | |||
| 3282 | /** |
||
| 3283 | * Copy file from another volume. |
||
| 3284 | * Return new file path or false. |
||
| 3285 | * |
||
| 3286 | * @param Object $volume source volume |
||
| 3287 | * @param string $src source file hash |
||
| 3288 | * @param string $destination destination dir path |
||
| 3289 | * @param string $name file name |
||
| 3290 | * @return string|false |
||
| 3291 | * @author Dmitry (dio) Levashov |
||
| 3292 | **/ |
||
| 3293 | protected function copyFrom($volume, $src, $destination, $name) { |
||
| 3355 | |||
| 3356 | /** |
||
| 3357 | * Remove file/ recursive remove dir |
||
| 3358 | * |
||
| 3359 | * @param string $path file path |
||
| 3360 | * @param bool $force try to remove even if file locked |
||
| 3361 | * @return bool |
||
| 3362 | * @author Dmitry (dio) Levashov |
||
| 3363 | **/ |
||
| 3364 | protected function remove($path, $force = false) { |
||
| 3394 | |||
| 3395 | |||
| 3396 | /************************* thumbnails **************************/ |
||
| 3397 | |||
| 3398 | /** |
||
| 3399 | * Return thumbnail file name for required file |
||
| 3400 | * |
||
| 3401 | * @param array $stat file stat |
||
| 3402 | * @return string |
||
| 3403 | * @author Dmitry (dio) Levashov |
||
| 3404 | **/ |
||
| 3405 | protected function tmbname($stat) { |
||
| 3408 | |||
| 3409 | /** |
||
| 3410 | * Return thumnbnail name if exists |
||
| 3411 | * |
||
| 3412 | * @param string $path file path |
||
| 3413 | * @param array $stat file stat |
||
| 3414 | * @return string|false |
||
| 3415 | * @author Dmitry (dio) Levashov |
||
| 3416 | **/ |
||
| 3417 | protected function gettmb($path, $stat) { |
||
| 3431 | |||
| 3432 | /** |
||
| 3433 | * Return true if thumnbnail for required file can be created |
||
| 3434 | * |
||
| 3435 | * @param string $path thumnbnail path |
||
| 3436 | * @param array $stat file stat |
||
| 3437 | * @param bool $checkTmbPath |
||
| 3438 | * @return string|bool |
||
| 3439 | * @author Dmitry (dio) Levashov |
||
| 3440 | **/ |
||
| 3441 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
| 3448 | |||
| 3449 | /** |
||
| 3450 | * Return true if required file can be resized. |
||
| 3451 | * By default - the same as canCreateTmb |
||
| 3452 | * |
||
| 3453 | * @param string $path thumnbnail path |
||
| 3454 | * @param array $stat file stat |
||
| 3455 | * @return string|bool |
||
| 3456 | * @author Dmitry (dio) Levashov |
||
| 3457 | **/ |
||
| 3458 | protected function canResize($path, $stat) { |
||
| 3461 | |||
| 3462 | /** |
||
| 3463 | * Create thumnbnail and return it's URL on success |
||
| 3464 | * |
||
| 3465 | * @param string $path file path |
||
| 3466 | * @param string $mime file mime type |
||
| 3467 | * @return string|false |
||
| 3468 | * @author Dmitry (dio) Levashov |
||
| 3469 | **/ |
||
| 3470 | protected function createTmb($path, $stat) { |
||
| 3540 | |||
| 3541 | /** |
||
| 3542 | * Resize image |
||
| 3543 | * |
||
| 3544 | * @param string $path image file |
||
| 3545 | * @param int $width new width |
||
| 3546 | * @param int $height new height |
||
| 3547 | * @param bool $keepProportions crop image |
||
| 3548 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 3549 | * @param string $destformat image destination format |
||
| 3550 | * @return string|false |
||
| 3551 | * @author Dmitry (dio) Levashov |
||
| 3552 | * @author Alexey Sukhotin |
||
| 3553 | **/ |
||
| 3554 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null) { |
||
| 3647 | |||
| 3648 | /** |
||
| 3649 | * Crop image |
||
| 3650 | * |
||
| 3651 | * @param string $path image file |
||
| 3652 | * @param int $width crop width |
||
| 3653 | * @param int $height crop height |
||
| 3654 | * @param bool $x crop left offset |
||
| 3655 | * @param bool $y crop top offset |
||
| 3656 | * @param string $destformat image destination format |
||
| 3657 | * @return string|false |
||
| 3658 | * @author Dmitry (dio) Levashov |
||
| 3659 | * @author Alexey Sukhotin |
||
| 3660 | **/ |
||
| 3661 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null) { |
||
| 3735 | |||
| 3736 | /** |
||
| 3737 | * Put image to square |
||
| 3738 | * |
||
| 3739 | * @param string $path image file |
||
| 3740 | * @param int $width square width |
||
| 3741 | * @param int $height square height |
||
| 3742 | * @param int $align reserved |
||
| 3743 | * @param int $valign reserved |
||
| 3744 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3745 | * @param string $destformat image destination format |
||
| 3746 | * @return string|false |
||
| 3747 | * @author Dmitry (dio) Levashov |
||
| 3748 | * @author Alexey Sukhotin |
||
| 3749 | **/ |
||
| 3750 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null) { |
||
| 3828 | |||
| 3829 | /** |
||
| 3830 | * Rotate image |
||
| 3831 | * |
||
| 3832 | * @param string $path image file |
||
| 3833 | * @param int $degree rotete degrees |
||
| 3834 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3835 | * @param string $destformat image destination format |
||
| 3836 | * @return string|false |
||
| 3837 | * @author nao-pon |
||
| 3838 | * @author Troex Nevelin |
||
| 3839 | **/ |
||
| 3840 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null) { |
||
| 3920 | |||
| 3921 | /** |
||
| 3922 | * Execute shell command |
||
| 3923 | * |
||
| 3924 | * @param string $command command line |
||
| 3925 | * @param array $output stdout strings |
||
| 3926 | * @param array $return_var process exit code |
||
| 3927 | * @param array $error_output stderr strings |
||
| 3928 | * @return int exit code |
||
| 3929 | * @author Alexey Sukhotin |
||
| 3930 | **/ |
||
| 3931 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
| 3961 | |||
| 3962 | /** |
||
| 3963 | * Remove thumbnail, also remove recursively if stat is directory |
||
| 3964 | * |
||
| 3965 | * @param string $stat file stat |
||
| 3966 | * @return void |
||
| 3967 | * @author Dmitry (dio) Levashov |
||
| 3968 | * @author Naoki Sawada |
||
| 3969 | * @author Troex Nevelin |
||
| 3970 | **/ |
||
| 3971 | protected function rmTmb($stat) { |
||
| 3984 | |||
| 3985 | /** |
||
| 3986 | * Create an gd image according to the specified mime type |
||
| 3987 | * |
||
| 3988 | * @param string $path image file |
||
| 3989 | * @param string $mime |
||
| 3990 | * @return gd image resource identifier |
||
| 3991 | */ |
||
| 3992 | protected function gdImageCreate($path,$mime){ |
||
| 4008 | |||
| 4009 | /** |
||
| 4010 | * Output gd image to file |
||
| 4011 | * |
||
| 4012 | * @param resource $image gd image resource |
||
| 4013 | * @param string $filename The path to save the file to. |
||
| 4014 | * @param string $destformat The Image type to use for $filename |
||
| 4015 | * @param string $mime The original image mime type |
||
| 4016 | */ |
||
| 4017 | protected function gdImage($image, $filename, $destformat, $mime ){ |
||
| 4029 | |||
| 4030 | /** |
||
| 4031 | * Assign the proper background to a gd image |
||
| 4032 | * |
||
| 4033 | * @param resource $image gd image resource |
||
| 4034 | * @param string $bgcolor background color in #rrggbb format |
||
| 4035 | */ |
||
| 4036 | protected function gdImageBackground($image, $bgcolor){ |
||
| 4049 | |||
| 4050 | /*********************** misc *************************/ |
||
| 4051 | |||
| 4052 | /** |
||
| 4053 | * Return smart formatted date |
||
| 4054 | * |
||
| 4055 | * @param int $ts file timestamp |
||
| 4056 | * @return string |
||
| 4057 | * @author Dmitry (dio) Levashov |
||
| 4058 | **/ |
||
| 4059 | // protected function formatDate($ts) { |
||
| 4060 | // if ($ts > $this->today) { |
||
| 4061 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 4062 | // } |
||
| 4063 | // |
||
| 4064 | // if ($ts > $this->yesterday) { |
||
| 4065 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 4066 | // } |
||
| 4067 | // |
||
| 4068 | // return date($this->options['dateFormat'], $ts); |
||
| 4069 | // } |
||
| 4070 | |||
| 4071 | /** |
||
| 4072 | * Find position of first occurrence of string in a string with multibyte support |
||
| 4073 | * |
||
| 4074 | * @param string $haystack The string being checked. |
||
| 4075 | * @param string $needle The string to find in haystack. |
||
| 4076 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 4077 | * @return int|bool |
||
| 4078 | * @author Alexey Sukhotin |
||
| 4079 | **/ |
||
| 4080 | protected function stripos($haystack , $needle , $offset = 0) { |
||
| 4088 | |||
| 4089 | /** |
||
| 4090 | * Get server side available archivers |
||
| 4091 | * |
||
| 4092 | * @param bool $use_cache |
||
| 4093 | * @return array |
||
| 4094 | */ |
||
| 4095 | protected function getArchivers($use_cache = true) { |
||
| 4211 | |||
| 4212 | /** |
||
| 4213 | * Resolve relative / (Unix-like)absolute path |
||
| 4214 | * |
||
| 4215 | * @param string $path target path |
||
| 4216 | * @param string $base base path |
||
| 4217 | * @return string |
||
| 4218 | */ |
||
| 4219 | protected function getFullPath($path, $base) { |
||
| 4266 | |||
| 4267 | /** |
||
| 4268 | * Remove directory recursive on local file system |
||
| 4269 | * |
||
| 4270 | * @param string $dir Target dirctory path |
||
| 4271 | * @return boolean |
||
| 4272 | * @author Naoki Sawada |
||
| 4273 | */ |
||
| 4274 | public function rmdirRecursive($dir) { |
||
| 4294 | |||
| 4295 | /** |
||
| 4296 | * Create archive and return its path |
||
| 4297 | * |
||
| 4298 | * @param string $dir target dir |
||
| 4299 | * @param array $files files names list |
||
| 4300 | * @param string $name archive name |
||
| 4301 | * @param array $arc archiver options |
||
| 4302 | * @return string|bool |
||
| 4303 | * @author Dmitry (dio) Levashov, |
||
| 4304 | * @author Alexey Sukhotin |
||
| 4305 | * @author Naoki Sawada |
||
| 4306 | **/ |
||
| 4307 | protected function makeArchive($dir, $files, $name, $arc) { |
||
| 4325 | |||
| 4326 | /** |
||
| 4327 | * Unpack archive |
||
| 4328 | * |
||
| 4329 | * @param string $path archive path |
||
| 4330 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 4331 | * @param bool $remove remove archive ( unlink($path) ) |
||
| 4332 | * @return void |
||
| 4333 | * @author Dmitry (dio) Levashov |
||
| 4334 | * @author Alexey Sukhotin |
||
| 4335 | * @author Naoki Sawada |
||
| 4336 | **/ |
||
| 4337 | protected function unpackArchive($path, $arc, $remove = true) { |
||
| 4352 | |||
| 4353 | /** |
||
| 4354 | * Create Zip archive using PHP class ZipArchive |
||
| 4355 | * |
||
| 4356 | * @param string $dir target dir |
||
| 4357 | * @param array $files files names list |
||
| 4358 | * @param string|object $zipPath Zip archive name |
||
| 4359 | * @return void |
||
| 4360 | * @author Naoki Sawada |
||
| 4361 | */ |
||
| 4362 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
| 4400 | |||
| 4401 | /** |
||
| 4402 | * Unpack Zip archive using PHP class ZipArchive |
||
| 4403 | * |
||
| 4404 | * @param string $zipPath Zip archive name |
||
| 4405 | * @param string $toDir Extract to path |
||
| 4406 | * @return bool |
||
| 4407 | * @author Naoki Sawada |
||
| 4408 | */ |
||
| 4409 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
| 4421 | |||
| 4422 | /**==================================* abstract methods *====================================**/ |
||
| 4423 | |||
| 4424 | /*********************** paths/urls *************************/ |
||
| 4425 | |||
| 4426 | /** |
||
| 4427 | * Return parent directory path |
||
| 4428 | * |
||
| 4429 | * @param string $path file path |
||
| 4430 | * @return string |
||
| 4431 | * @author Dmitry (dio) Levashov |
||
| 4432 | **/ |
||
| 4433 | abstract protected function _dirname($path); |
||
| 4434 | |||
| 4435 | /** |
||
| 4436 | * Return file name |
||
| 4437 | * |
||
| 4438 | * @param string $path file path |
||
| 4439 | * @return string |
||
| 4440 | * @author Dmitry (dio) Levashov |
||
| 4441 | **/ |
||
| 4442 | abstract protected function _basename($path); |
||
| 4443 | |||
| 4444 | /** |
||
| 4445 | * Join dir name and file name and return full path. |
||
| 4446 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 4447 | * |
||
| 4448 | * @param string $dir dir path |
||
| 4449 | * @param string $name file name |
||
| 4450 | * @return string |
||
| 4451 | * @author Dmitry (dio) Levashov |
||
| 4452 | **/ |
||
| 4453 | abstract protected function _joinPath($dir, $name); |
||
| 4454 | |||
| 4455 | /** |
||
| 4456 | * Return normalized path |
||
| 4457 | * |
||
| 4458 | * @param string $path file path |
||
| 4459 | * @return string |
||
| 4460 | * @author Dmitry (dio) Levashov |
||
| 4461 | **/ |
||
| 4462 | abstract protected function _normpath($path); |
||
| 4463 | |||
| 4464 | /** |
||
| 4465 | * Return file path related to root dir |
||
| 4466 | * |
||
| 4467 | * @param string $path file path |
||
| 4468 | * @return string |
||
| 4469 | * @author Dmitry (dio) Levashov |
||
| 4470 | **/ |
||
| 4471 | abstract protected function _relpath($path); |
||
| 4472 | |||
| 4473 | /** |
||
| 4474 | * Convert path related to root dir into real path |
||
| 4475 | * |
||
| 4476 | * @param string $path rel file path |
||
| 4477 | * @return string |
||
| 4478 | * @author Dmitry (dio) Levashov |
||
| 4479 | **/ |
||
| 4480 | abstract protected function _abspath($path); |
||
| 4481 | |||
| 4482 | /** |
||
| 4483 | * Return fake path started from root dir. |
||
| 4484 | * Required to show path on client side. |
||
| 4485 | * |
||
| 4486 | * @param string $path file path |
||
| 4487 | * @return string |
||
| 4488 | * @author Dmitry (dio) Levashov |
||
| 4489 | **/ |
||
| 4490 | abstract protected function _path($path); |
||
| 4491 | |||
| 4492 | /** |
||
| 4493 | * Return true if $path is children of $parent |
||
| 4494 | * |
||
| 4495 | * @param string $path path to check |
||
| 4496 | * @param string $parent parent path |
||
| 4497 | * @return bool |
||
| 4498 | * @author Dmitry (dio) Levashov |
||
| 4499 | **/ |
||
| 4500 | abstract protected function _inpath($path, $parent); |
||
| 4501 | |||
| 4502 | /** |
||
| 4503 | * Return stat for given path. |
||
| 4504 | * Stat contains following fields: |
||
| 4505 | * - (int) size file size in b. required |
||
| 4506 | * - (int) ts file modification time in unix time. required |
||
| 4507 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 4508 | * - (bool) read read permissions. required |
||
| 4509 | * - (bool) write write permissions. required |
||
| 4510 | * - (bool) locked is object locked. optionally |
||
| 4511 | * - (bool) hidden is object hidden. optionally |
||
| 4512 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 4513 | * - (string) target for symlinks - link target path. optionally |
||
| 4514 | * |
||
| 4515 | * If file does not exists - returns empty array or false. |
||
| 4516 | * |
||
| 4517 | * @param string $path file path |
||
| 4518 | * @return array|false |
||
| 4519 | * @author Dmitry (dio) Levashov |
||
| 4520 | **/ |
||
| 4521 | abstract protected function _stat($path); |
||
| 4522 | |||
| 4523 | |||
| 4524 | /***************** file stat ********************/ |
||
| 4525 | |||
| 4526 | |||
| 4527 | /** |
||
| 4528 | * Return true if path is dir and has at least one childs directory |
||
| 4529 | * |
||
| 4530 | * @param string $path dir path |
||
| 4531 | * @return bool |
||
| 4532 | * @author Dmitry (dio) Levashov |
||
| 4533 | **/ |
||
| 4534 | abstract protected function _subdirs($path); |
||
| 4535 | |||
| 4536 | /** |
||
| 4537 | * Return object width and height |
||
| 4538 | * Ususaly used for images, but can be realize for video etc... |
||
| 4539 | * |
||
| 4540 | * @param string $path file path |
||
| 4541 | * @param string $mime file mime type |
||
| 4542 | * @return string |
||
| 4543 | * @author Dmitry (dio) Levashov |
||
| 4544 | **/ |
||
| 4545 | abstract protected function _dimensions($path, $mime); |
||
| 4546 | |||
| 4547 | /******************** file/dir content *********************/ |
||
| 4548 | |||
| 4549 | /** |
||
| 4550 | * Return files list in directory |
||
| 4551 | * |
||
| 4552 | * @param string $path dir path |
||
| 4553 | * @return array |
||
| 4554 | * @author Dmitry (dio) Levashov |
||
| 4555 | **/ |
||
| 4556 | abstract protected function _scandir($path); |
||
| 4557 | |||
| 4558 | /** |
||
| 4559 | * Open file and return file pointer |
||
| 4560 | * |
||
| 4561 | * @param string $path file path |
||
| 4562 | * @param bool $write open file for writing |
||
| 4563 | * @return resource|false |
||
| 4564 | * @author Dmitry (dio) Levashov |
||
| 4565 | **/ |
||
| 4566 | abstract protected function _fopen($path, $mode="rb"); |
||
| 4567 | |||
| 4568 | /** |
||
| 4569 | * Close opened file |
||
| 4570 | * |
||
| 4571 | * @param resource $fp file pointer |
||
| 4572 | * @param string $path file path |
||
| 4573 | * @return bool |
||
| 4574 | * @author Dmitry (dio) Levashov |
||
| 4575 | **/ |
||
| 4576 | abstract protected function _fclose($fp, $path=''); |
||
| 4577 | |||
| 4578 | /******************** file/dir manipulations *************************/ |
||
| 4579 | |||
| 4580 | /** |
||
| 4581 | * Create dir and return created dir path or false on failed |
||
| 4582 | * |
||
| 4583 | * @param string $path parent dir path |
||
| 4584 | * @param string $name new directory name |
||
| 4585 | * @return string|bool |
||
| 4586 | * @author Dmitry (dio) Levashov |
||
| 4587 | **/ |
||
| 4588 | abstract protected function _mkdir($path, $name); |
||
| 4589 | |||
| 4590 | /** |
||
| 4591 | * Create file and return it's path or false on failed |
||
| 4592 | * |
||
| 4593 | * @param string $path parent dir path |
||
| 4594 | * @param string $name new file name |
||
| 4595 | * @return string|bool |
||
| 4596 | * @author Dmitry (dio) Levashov |
||
| 4597 | **/ |
||
| 4598 | abstract protected function _mkfile($path, $name); |
||
| 4599 | |||
| 4600 | /** |
||
| 4601 | * Create symlink |
||
| 4602 | * |
||
| 4603 | * @param string $source file to link to |
||
| 4604 | * @param string $targetDir folder to create link in |
||
| 4605 | * @param string $name symlink name |
||
| 4606 | * @return bool |
||
| 4607 | * @author Dmitry (dio) Levashov |
||
| 4608 | **/ |
||
| 4609 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 4610 | |||
| 4611 | /** |
||
| 4612 | * Copy file into another file (only inside one volume) |
||
| 4613 | * |
||
| 4614 | * @param string $source source file path |
||
| 4615 | * @param string $target target dir path |
||
| 4616 | * @param string $name file name |
||
| 4617 | * @return bool |
||
| 4618 | * @author Dmitry (dio) Levashov |
||
| 4619 | **/ |
||
| 4620 | abstract protected function _copy($source, $targetDir, $name); |
||
| 4621 | |||
| 4622 | /** |
||
| 4623 | * Move file into another parent dir. |
||
| 4624 | * Return new file path or false. |
||
| 4625 | * |
||
| 4626 | * @param string $source source file path |
||
| 4627 | * @param string $target target dir path |
||
| 4628 | * @param string $name file name |
||
| 4629 | * @return string|bool |
||
| 4630 | * @author Dmitry (dio) Levashov |
||
| 4631 | **/ |
||
| 4632 | abstract protected function _move($source, $targetDir, $name); |
||
| 4633 | |||
| 4634 | /** |
||
| 4635 | * Remove file |
||
| 4636 | * |
||
| 4637 | * @param string $path file path |
||
| 4638 | * @return bool |
||
| 4639 | * @author Dmitry (dio) Levashov |
||
| 4640 | **/ |
||
| 4641 | abstract protected function _unlink($path); |
||
| 4642 | |||
| 4643 | /** |
||
| 4644 | * Remove dir |
||
| 4645 | * |
||
| 4646 | * @param string $path dir path |
||
| 4647 | * @return bool |
||
| 4648 | * @author Dmitry (dio) Levashov |
||
| 4649 | **/ |
||
| 4650 | abstract protected function _rmdir($path); |
||
| 4651 | |||
| 4652 | /** |
||
| 4653 | * Create new file and write into it from file pointer. |
||
| 4654 | * Return new file path or false on error. |
||
| 4655 | * |
||
| 4656 | * @param resource $fp file pointer |
||
| 4657 | * @param string $dir target dir path |
||
| 4658 | * @param string $name file name |
||
| 4659 | * @param array $stat file stat (required by some virtual fs) |
||
| 4660 | * @return bool|string |
||
| 4661 | * @author Dmitry (dio) Levashov |
||
| 4662 | **/ |
||
| 4663 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 4664 | |||
| 4665 | /** |
||
| 4666 | * Get file contents |
||
| 4667 | * |
||
| 4668 | * @param string $path file path |
||
| 4669 | * @return string|false |
||
| 4670 | * @author Dmitry (dio) Levashov |
||
| 4671 | **/ |
||
| 4672 | abstract protected function _getContents($path); |
||
| 4673 | |||
| 4674 | /** |
||
| 4675 | * Write a string to a file |
||
| 4676 | * |
||
| 4677 | * @param string $path file path |
||
| 4678 | * @param string $content new file content |
||
| 4679 | * @return bool |
||
| 4680 | * @author Dmitry (dio) Levashov |
||
| 4681 | **/ |
||
| 4682 | abstract protected function _filePutContents($path, $content); |
||
| 4683 | |||
| 4684 | /** |
||
| 4685 | * Extract files from archive |
||
| 4686 | * |
||
| 4687 | * @param string $path file path |
||
| 4688 | * @param array $arc archiver options |
||
| 4689 | * @return bool |
||
| 4690 | * @author Dmitry (dio) Levashov, |
||
| 4691 | * @author Alexey Sukhotin |
||
| 4692 | **/ |
||
| 4693 | abstract protected function _extract($path, $arc); |
||
| 4694 | |||
| 4695 | /** |
||
| 4696 | * Create archive and return its path |
||
| 4697 | * |
||
| 4698 | * @param string $dir target dir |
||
| 4699 | * @param array $files files names list |
||
| 4700 | * @param string $name archive name |
||
| 4701 | * @param array $arc archiver options |
||
| 4702 | * @return string|bool |
||
| 4703 | * @author Dmitry (dio) Levashov, |
||
| 4704 | * @author Alexey Sukhotin |
||
| 4705 | **/ |
||
| 4706 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 4707 | |||
| 4708 | /** |
||
| 4709 | * Detect available archivers |
||
| 4710 | * |
||
| 4711 | * @return void |
||
| 4712 | * @author Dmitry (dio) Levashov, |
||
| 4713 | * @author Alexey Sukhotin |
||
| 4714 | **/ |
||
| 4715 | abstract protected function _checkArchivers(); |
||
| 4716 | |||
| 4717 | /** |
||
| 4718 | * Change file mode (chmod) |
||
| 4719 | * |
||
| 4720 | * @param string $path file path |
||
| 4721 | * @param string $mode octal string such as '0755' |
||
| 4722 | * @return bool |
||
| 4723 | * @author David Bartle, |
||
| 4724 | **/ |
||
| 4725 | abstract protected function _chmod($path, $mode); |
||
| 4726 | |||
| 4727 | |||
| 4728 | } // END class |
||
| 4729 |
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.