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 elFinder 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 elFinder, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class elFinder { |
||
|
|
|||
| 13 | |||
| 14 | /** |
||
| 15 | * API version number |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | **/ |
||
| 19 | protected $version = '2.0'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Storages (root dirs) |
||
| 23 | * |
||
| 24 | * @var array |
||
| 25 | **/ |
||
| 26 | protected $volumes = array(); |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Network mount drivers |
||
| 30 | * |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | public static $netDrivers = array(); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * elFinder global locale |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | public static $locale = ''; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * elFinder global sessionCacheKey |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | public static $sessionCacheKey = ''; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * elFinder base64encodeSessionData |
||
| 51 | * elFinder save session data as `UTF-8` |
||
| 52 | * If the session storage mechanism of the system does not allow `UTF-8` |
||
| 53 | * And it must be `true` option 'base64encodeSessionData' of elFinder |
||
| 54 | * |
||
| 55 | * @var bool |
||
| 56 | */ |
||
| 57 | protected static $base64encodeSessionData = false; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Session key of net mount volumes |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | protected $netVolumesSessionKey = ''; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Mounted volumes count |
||
| 67 | * Required to create unique volume id |
||
| 68 | * |
||
| 69 | * @var int |
||
| 70 | **/ |
||
| 71 | public static $volumesCnt = 1; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Default root (storage) |
||
| 75 | * |
||
| 76 | * @var elFinderStorageDriver |
||
| 77 | **/ |
||
| 78 | protected $default = null; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Commands and required arguments list |
||
| 82 | * |
||
| 83 | * @var array |
||
| 84 | **/ |
||
| 85 | protected $commands = array( |
||
| 86 | 'open' => array('target' => false, 'tree' => false, 'init' => false, 'mimes' => false, 'compare' => false), |
||
| 87 | 'ls' => array('target' => true, 'mimes' => false), |
||
| 88 | 'tree' => array('target' => true), |
||
| 89 | 'parents' => array('target' => true), |
||
| 90 | 'tmb' => array('targets' => true), |
||
| 91 | 'file' => array('target' => true, 'download' => false), |
||
| 92 | 'size' => array('targets' => true), |
||
| 93 | 'mkdir' => array('target' => true, 'name' => true), |
||
| 94 | 'mkfile' => array('target' => true, 'name' => true, 'mimes' => false), |
||
| 95 | 'rm' => array('targets' => true), |
||
| 96 | 'rename' => array('target' => true, 'name' => true, 'mimes' => false), |
||
| 97 | 'duplicate' => array('targets' => true, 'suffix' => false), |
||
| 98 | 'paste' => array('dst' => true, 'targets' => true, 'cut' => false, 'mimes' => false, 'renames' => false, 'suffix' => false), |
||
| 99 | 'upload' => array('target' => true, 'FILES' => true, 'mimes' => false, 'html' => false, 'upload' => false, 'name' => false, 'upload_path' => false, 'chunk' => false, 'cid' => false, 'node' => false, 'renames' => false, 'suffix' => false), |
||
| 100 | 'get' => array('target' => true, 'conv' => false), |
||
| 101 | 'put' => array('target' => true, 'content' => '', 'mimes' => false), |
||
| 102 | 'archive' => array('targets' => true, 'type' => true, 'mimes' => false, 'name' => false), |
||
| 103 | 'extract' => array('target' => true, 'mimes' => false, 'makedir' => false), |
||
| 104 | 'search' => array('q' => true, 'mimes' => false, 'target' => false), |
||
| 105 | 'info' => array('targets' => true, 'compare' => false), |
||
| 106 | 'dim' => array('target' => true), |
||
| 107 | 'resize' => array('target' => true, 'width' => true, 'height' => true, 'mode' => false, 'x' => false, 'y' => false, 'degree' => false, 'quality' => false), |
||
| 108 | 'netmount' => array('protocol' => true, 'host' => true, 'path' => false, 'port' => false, 'user' => false, 'pass' => false, 'alias' => false, 'options' => false), |
||
| 109 | 'url' => array('target' => true, 'options' => false), |
||
| 110 | 'callback' => array('node' => true, 'json' => false, 'bind' => false, 'done' => false), |
||
| 111 | 'chmod' => array('targets' => true, 'mode' => true) |
||
| 112 | ); |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Plugins instance |
||
| 116 | * |
||
| 117 | * @var array |
||
| 118 | **/ |
||
| 119 | protected $plugins = array(); |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Commands listeners |
||
| 123 | * |
||
| 124 | * @var array |
||
| 125 | **/ |
||
| 126 | protected $listeners = array(); |
||
| 127 | |||
| 128 | /** |
||
| 129 | * script work time for debug |
||
| 130 | * |
||
| 131 | * @var string |
||
| 132 | **/ |
||
| 133 | protected $time = 0; |
||
| 134 | /** |
||
| 135 | * Is elFinder init correctly? |
||
| 136 | * |
||
| 137 | * @var bool |
||
| 138 | **/ |
||
| 139 | protected $loaded = false; |
||
| 140 | /** |
||
| 141 | * Send debug to client? |
||
| 142 | * |
||
| 143 | * @var string |
||
| 144 | **/ |
||
| 145 | protected $debug = false; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Call `session_write_close()` before exec command? |
||
| 149 | * |
||
| 150 | * @var bool |
||
| 151 | */ |
||
| 152 | protected $sessionCloseEarlier = true; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * SESSION use commands default is `netmount`, `netunmount` @see __construct() |
||
| 156 | * |
||
| 157 | * @var array |
||
| 158 | */ |
||
| 159 | protected $sessionUseCmds = array(); |
||
| 160 | |||
| 161 | /** |
||
| 162 | * session expires timeout |
||
| 163 | * |
||
| 164 | * @var int |
||
| 165 | **/ |
||
| 166 | protected $timeout = 0; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Temp dir path for Upload |
||
| 170 | * |
||
| 171 | * @var string |
||
| 172 | */ |
||
| 173 | protected $uploadTempPath = ''; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * undocumented class variable |
||
| 177 | * |
||
| 178 | * @var string |
||
| 179 | **/ |
||
| 180 | protected $uploadDebug = ''; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Errors from not mounted volumes |
||
| 184 | * |
||
| 185 | * @var array |
||
| 186 | **/ |
||
| 187 | public $mountErrors = array(); |
||
| 188 | |||
| 189 | /** |
||
| 190 | * URL for callback output window for CORS |
||
| 191 | * redirect to this URL when callback output |
||
| 192 | * |
||
| 193 | * @var string URL |
||
| 194 | */ |
||
| 195 | protected $callbackWindowURL = ''; |
||
| 196 | |||
| 197 | // Errors messages |
||
| 198 | const ERROR_UNKNOWN = 'errUnknown'; |
||
| 199 | const ERROR_UNKNOWN_CMD = 'errUnknownCmd'; |
||
| 200 | const ERROR_CONF = 'errConf'; |
||
| 201 | const ERROR_CONF_NO_JSON = 'errJSON'; |
||
| 202 | const ERROR_CONF_NO_VOL = 'errNoVolumes'; |
||
| 203 | const ERROR_INV_PARAMS = 'errCmdParams'; |
||
| 204 | const ERROR_OPEN = 'errOpen'; |
||
| 205 | const ERROR_DIR_NOT_FOUND = 'errFolderNotFound'; |
||
| 206 | const ERROR_FILE_NOT_FOUND = 'errFileNotFound'; // 'File not found.' |
||
| 207 | const ERROR_TRGDIR_NOT_FOUND = 'errTrgFolderNotFound'; // 'Target folder "$1" not found.' |
||
| 208 | const ERROR_NOT_DIR = 'errNotFolder'; |
||
| 209 | const ERROR_NOT_FILE = 'errNotFile'; |
||
| 210 | const ERROR_PERM_DENIED = 'errPerm'; |
||
| 211 | const ERROR_LOCKED = 'errLocked'; // '"$1" is locked and can not be renamed, moved or removed.' |
||
| 212 | const ERROR_EXISTS = 'errExists'; // 'File named "$1" already exists.' |
||
| 213 | const ERROR_INVALID_NAME = 'errInvName'; // 'Invalid file name.' |
||
| 214 | const ERROR_MKDIR = 'errMkdir'; |
||
| 215 | const ERROR_MKFILE = 'errMkfile'; |
||
| 216 | const ERROR_RENAME = 'errRename'; |
||
| 217 | const ERROR_COPY = 'errCopy'; |
||
| 218 | const ERROR_MOVE = 'errMove'; |
||
| 219 | const ERROR_COPY_FROM = 'errCopyFrom'; |
||
| 220 | const ERROR_COPY_TO = 'errCopyTo'; |
||
| 221 | const ERROR_COPY_ITSELF = 'errCopyInItself'; |
||
| 222 | const ERROR_REPLACE = 'errReplace'; // 'Unable to replace "$1".' |
||
| 223 | const ERROR_RM = 'errRm'; // 'Unable to remove "$1".' |
||
| 224 | const ERROR_RM_SRC = 'errRmSrc'; // 'Unable remove source file(s)' |
||
| 225 | const ERROR_MKOUTLINK = 'errMkOutLink'; // 'Unable to create a link to outside the volume root.' |
||
| 226 | const ERROR_UPLOAD = 'errUpload'; // 'Upload error.' |
||
| 227 | const ERROR_UPLOAD_FILE = 'errUploadFile'; // 'Unable to upload "$1".' |
||
| 228 | const ERROR_UPLOAD_NO_FILES = 'errUploadNoFiles'; // 'No files found for upload.' |
||
| 229 | const ERROR_UPLOAD_TOTAL_SIZE = 'errUploadTotalSize'; // 'Data exceeds the maximum allowed size.' |
||
| 230 | const ERROR_UPLOAD_FILE_SIZE = 'errUploadFileSize'; // 'File exceeds maximum allowed size.' |
||
| 231 | const ERROR_UPLOAD_FILE_MIME = 'errUploadMime'; // 'File type not allowed.' |
||
| 232 | const ERROR_UPLOAD_TRANSFER = 'errUploadTransfer'; // '"$1" transfer error.' |
||
| 233 | const ERROR_UPLOAD_TEMP = 'errUploadTemp'; // 'Unable to make temporary file for upload.' |
||
| 234 | // const ERROR_ACCESS_DENIED = 'errAccess'; |
||
| 235 | const ERROR_NOT_REPLACE = 'errNotReplace'; // Object "$1" already exists at this location and can not be replaced with object of another type. |
||
| 236 | const ERROR_SAVE = 'errSave'; |
||
| 237 | const ERROR_EXTRACT = 'errExtract'; |
||
| 238 | const ERROR_ARCHIVE = 'errArchive'; |
||
| 239 | const ERROR_NOT_ARCHIVE = 'errNoArchive'; |
||
| 240 | const ERROR_ARCHIVE_TYPE = 'errArcType'; |
||
| 241 | const ERROR_ARC_SYMLINKS = 'errArcSymlinks'; |
||
| 242 | const ERROR_ARC_MAXSIZE = 'errArcMaxSize'; |
||
| 243 | const ERROR_RESIZE = 'errResize'; |
||
| 244 | const ERROR_UNSUPPORT_TYPE = 'errUsupportType'; |
||
| 245 | const ERROR_CONV_UTF8 = 'errConvUTF8'; |
||
| 246 | const ERROR_NOT_UTF8_CONTENT = 'errNotUTF8Content'; |
||
| 247 | const ERROR_NETMOUNT = 'errNetMount'; |
||
| 248 | const ERROR_NETUNMOUNT = 'errNetUnMount'; |
||
| 249 | const ERROR_NETMOUNT_NO_DRIVER = 'errNetMountNoDriver'; |
||
| 250 | const ERROR_NETMOUNT_FAILED = 'errNetMountFailed'; |
||
| 251 | |||
| 252 | const ERROR_SESSION_EXPIRES = 'errSessionExpires'; |
||
| 253 | |||
| 254 | const ERROR_CREATING_TEMP_DIR = 'errCreatingTempDir'; |
||
| 255 | const ERROR_FTP_DOWNLOAD_FILE = 'errFtpDownloadFile'; |
||
| 256 | const ERROR_FTP_UPLOAD_FILE = 'errFtpUploadFile'; |
||
| 257 | const ERROR_FTP_MKDIR = 'errFtpMkdir'; |
||
| 258 | const ERROR_ARCHIVE_EXEC = 'errArchiveExec'; |
||
| 259 | const ERROR_EXTRACT_EXEC = 'errExtractExec'; |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Constructor |
||
| 263 | * |
||
| 264 | * @param array elFinder and roots configurations |
||
| 265 | * @return void |
||
| 266 | * @author Dmitry (dio) Levashov |
||
| 267 | **/ |
||
| 268 | public function __construct($opts) { |
||
| 269 | if (session_id() == '') { |
||
| 270 | session_start(); |
||
| 271 | } |
||
| 272 | $sessionUseCmds = array('netmount', 'netunmount'); |
||
| 273 | if (isset($opts['sessionUseCmds']) && is_array($opts['sessionUseCmds'])) { |
||
| 274 | $sessionUseCmds = array_merge($sessionUseCmds, $opts['sessionUseCmds']); |
||
| 275 | } |
||
| 276 | |||
| 277 | // set self::$volumesCnt by HTTP header "X-elFinder-VolumesCntStart" |
||
| 278 | if (isset($_SERVER['HTTP_X_ELFINDER_VOLUMESCNTSTART']) && ($volumesCntStart = intval($_SERVER['HTTP_X_ELFINDER_VOLUMESCNTSTART']))) { |
||
| 279 | self::$volumesCnt = $volumesCntStart; |
||
| 280 | } |
||
| 281 | |||
| 282 | $this->time = $this->utime(); |
||
| 283 | $this->debug = (isset($opts['debug']) && $opts['debug'] ? true : false); |
||
| 284 | $this->sessionCloseEarlier = isset($opts['sessionCloseEarlier'])? (bool)$opts['sessionCloseEarlier'] : true; |
||
| 285 | $this->sessionUseCmds = array_flip($sessionUseCmds); |
||
| 286 | $this->timeout = (isset($opts['timeout']) ? $opts['timeout'] : 0); |
||
| 287 | $this->uploadTempPath = (isset($opts['uploadTempPath']) ? $opts['uploadTempPath'] : ''); |
||
| 288 | $this->netVolumesSessionKey = !empty($opts['netVolumesSessionKey'])? $opts['netVolumesSessionKey'] : 'elFinderNetVolumes'; |
||
| 289 | $this->callbackWindowURL = (isset($opts['callbackWindowURL']) ? $opts['callbackWindowURL'] : ''); |
||
| 290 | self::$sessionCacheKey = !empty($opts['sessionCacheKey']) ? $opts['sessionCacheKey'] : 'elFinderCaches'; |
||
| 291 | |||
| 292 | // check session cache |
||
| 293 | $_optsMD5 = md5(json_encode($opts['roots'])); |
||
| 294 | if (! isset($_SESSION[self::$sessionCacheKey]) || $_SESSION[self::$sessionCacheKey]['_optsMD5'] !== $_optsMD5) { |
||
| 295 | $_SESSION[self::$sessionCacheKey] = array( |
||
| 296 | '_optsMD5' => $_optsMD5 |
||
| 297 | ); |
||
| 298 | } |
||
| 299 | self::$base64encodeSessionData = !empty($opts['base64encodeSessionData']); |
||
| 300 | |||
| 301 | // setlocale and global locale regists to elFinder::locale |
||
| 302 | self::$locale = !empty($opts['locale']) ? $opts['locale'] : 'en_US.UTF-8'; |
||
| 303 | if (false === @setlocale(LC_ALL, self::$locale)) { |
||
| 304 | self::$locale = setlocale(LC_ALL, ''); |
||
| 305 | } |
||
| 306 | |||
| 307 | // bind events listeners |
||
| 308 | if (!empty($opts['bind']) && is_array($opts['bind'])) { |
||
| 309 | $_req = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET; |
||
| 310 | $_reqCmd = isset($_req['cmd']) ? $_req['cmd'] : ''; |
||
| 311 | foreach ($opts['bind'] as $cmd => $handlers) { |
||
| 312 | $doRegist = (strpos($cmd, '*') !== false); |
||
| 313 | if (! $doRegist) { |
||
| 314 | $_getcmd = create_function('$cmd', 'list($ret) = explode(\'.\', $cmd);return trim($ret);'); |
||
| 315 | $doRegist = ($_reqCmd && in_array($_reqCmd, array_map($_getcmd, explode(' ', $cmd)))); |
||
| 316 | } |
||
| 317 | if ($doRegist) { |
||
| 318 | if (! is_array($handlers) || is_object($handlers[0])) { |
||
| 319 | $handlers = array($handlers); |
||
| 320 | } |
||
| 321 | foreach($handlers as $handler) { |
||
| 322 | if ($handler) { |
||
| 323 | if (is_string($handler) && strpos($handler, '.')) { |
||
| 324 | list($_domain, $_name, $_method) = array_pad(explode('.', $handler), 3, ''); |
||
| 325 | if (strcasecmp($_domain, 'plugin') === 0) { |
||
| 326 | if ($plugin = $this->getPluginInstance($_name, isset($opts['plugin'][$_name])? $opts['plugin'][$_name] : array()) |
||
| 327 | and method_exists($plugin, $_method)) { |
||
| 328 | $this->bind($cmd, array($plugin, $_method)); |
||
| 329 | } |
||
| 330 | } |
||
| 331 | } else { |
||
| 332 | $this->bind($cmd, $handler); |
||
| 333 | } |
||
| 334 | } |
||
| 335 | } |
||
| 336 | } |
||
| 337 | } |
||
| 338 | } |
||
| 339 | |||
| 340 | if (!isset($opts['roots']) || !is_array($opts['roots'])) { |
||
| 341 | $opts['roots'] = array(); |
||
| 342 | } |
||
| 343 | |||
| 344 | // check for net volumes stored in session |
||
| 345 | foreach ($this->getNetVolumes() as $key => $root) { |
||
| 346 | $opts['roots'][$key] = $root; |
||
| 347 | } |
||
| 348 | |||
| 349 | // "mount" volumes |
||
| 350 | foreach ($opts['roots'] as $i => $o) { |
||
| 351 | $class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : ''); |
||
| 352 | |||
| 353 | if (class_exists($class)) { |
||
| 354 | $volume = new $class(); |
||
| 355 | |||
| 356 | try { |
||
| 357 | if ($volume->mount($o)) { |
||
| 358 | // unique volume id (ends on "_") - used as prefix to files hash |
||
| 359 | $id = $volume->id(); |
||
| 360 | |||
| 361 | $this->volumes[$id] = $volume; |
||
| 362 | if ((!$this->default || $volume->root() !== $volume->defaultPath()) && $volume->isReadable()) { |
||
| 363 | $this->default = $this->volumes[$id]; |
||
| 364 | } |
||
| 365 | } else { |
||
| 366 | $this->removeNetVolume($i); |
||
| 367 | $this->mountErrors[] = 'Driver "'.$class.'" : '.implode(' ', $volume->error()); |
||
| 368 | } |
||
| 369 | } catch (Exception $e) { |
||
| 370 | $this->removeNetVolume($i); |
||
| 371 | $this->mountErrors[] = 'Driver "'.$class.'" : '.$e->getMessage(); |
||
| 372 | } |
||
| 373 | } else { |
||
| 374 | $this->mountErrors[] = 'Driver "'.$class.'" does not exists'; |
||
| 375 | } |
||
| 376 | } |
||
| 377 | |||
| 378 | // if at least one readable volume - ii desu >_< |
||
| 379 | $this->loaded = !empty($this->default); |
||
| 380 | } |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Return true if fm init correctly |
||
| 384 | * |
||
| 385 | * @return bool |
||
| 386 | * @author Dmitry (dio) Levashov |
||
| 387 | **/ |
||
| 388 | public function loaded() { |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Return version (api) number |
||
| 394 | * |
||
| 395 | * @return string |
||
| 396 | * @author Dmitry (dio) Levashov |
||
| 397 | **/ |
||
| 398 | public function version() { |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Add handler to elFinder command |
||
| 404 | * |
||
| 405 | * @param string command name |
||
| 406 | * @param string|array callback name or array(object, method) |
||
| 407 | * @return elFinder |
||
| 408 | * @author Dmitry (dio) Levashov |
||
| 409 | **/ |
||
| 410 | public function bind($cmd, $handler) { |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Remove event (command exec) handler |
||
| 446 | * |
||
| 447 | * @param string command name |
||
| 448 | * @param string|array callback name or array(object, method) |
||
| 449 | * @return elFinder |
||
| 450 | * @author Dmitry (dio) Levashov |
||
| 451 | **/ |
||
| 452 | public function unbind($cmd, $handler) { |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Return true if command exists |
||
| 466 | * |
||
| 467 | * @param string command name |
||
| 468 | * @return bool |
||
| 469 | * @author Dmitry (dio) Levashov |
||
| 470 | **/ |
||
| 471 | public function commandExists($cmd) { |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Return root - file's owner (public func of volume()) |
||
| 477 | * |
||
| 478 | * @param string file hash |
||
| 479 | * @return elFinderStorageDriver |
||
| 480 | * @author Naoki Sawada |
||
| 481 | */ |
||
| 482 | public function getVolume($hash) { |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Return command required arguments info |
||
| 488 | * |
||
| 489 | * @param string command name |
||
| 490 | * @return array |
||
| 491 | * @author Dmitry (dio) Levashov |
||
| 492 | **/ |
||
| 493 | public function commandArgsList($cmd) { |
||
| 496 | |||
| 497 | private function session_expires() { |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Exec command and return result |
||
| 514 | * |
||
| 515 | * @param string $cmd command name |
||
| 516 | * @param array $args command arguments |
||
| 517 | * @return array |
||
| 518 | * @author Dmitry (dio) Levashov |
||
| 519 | **/ |
||
| 520 | public function exec($cmd, $args) { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Return file real path |
||
| 626 | * |
||
| 627 | * @param string $hash file hash |
||
| 628 | * @return string |
||
| 629 | * @author Dmitry (dio) Levashov |
||
| 630 | **/ |
||
| 631 | public function realpath($hash) { |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Return network volumes config. |
||
| 640 | * |
||
| 641 | * @return array |
||
| 642 | * @author Dmitry (dio) Levashov |
||
| 643 | */ |
||
| 644 | protected function getNetVolumes() { |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Save network volumes config. |
||
| 655 | * |
||
| 656 | * @param array $volumes volumes config |
||
| 657 | * @return void |
||
| 658 | * @author Dmitry (dio) Levashov |
||
| 659 | */ |
||
| 660 | protected function saveNetVolumes($volumes) { |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Remove netmount volume |
||
| 666 | * |
||
| 667 | * @param string $key netvolume key |
||
| 668 | */ |
||
| 669 | protected function removeNetVolume($key) { |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Get plugin instance & set to $this->plugins |
||
| 679 | * |
||
| 680 | * @param string $name Plugin name (dirctory name) |
||
| 681 | * @param array $opts Plugin options (optional) |
||
| 682 | * @return object | bool Plugin object instance Or false |
||
| 683 | * @author Naoki Sawada |
||
| 684 | */ |
||
| 685 | protected function getPluginInstance($name, $opts = array()) { |
||
| 699 | |||
| 700 | /***************************************************************************/ |
||
| 701 | /* commands */ |
||
| 702 | /***************************************************************************/ |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Normalize error messages |
||
| 706 | * |
||
| 707 | * @return array |
||
| 708 | * @author Dmitry (dio) Levashov |
||
| 709 | **/ |
||
| 710 | public function error() { |
||
| 723 | |||
| 724 | protected function netmount($args) { |
||
| 799 | |||
| 800 | /** |
||
| 801 | * "Open" directory |
||
| 802 | * Return array with following elements |
||
| 803 | * - cwd - opened dir info |
||
| 804 | * - files - opened dir content [and dirs tree if $args[tree]] |
||
| 805 | * - api - api version (if $args[init]) |
||
| 806 | * - uplMaxSize - if $args[init] |
||
| 807 | * - error - on failed |
||
| 808 | * |
||
| 809 | * @param array command arguments |
||
| 810 | * @return array |
||
| 811 | * @author Dmitry (dio) Levashov |
||
| 812 | **/ |
||
| 813 | protected function open($args) { |
||
| 911 | |||
| 912 | /** |
||
| 913 | * Return dir files names list |
||
| 914 | * |
||
| 915 | * @param array command arguments |
||
| 916 | * @return array |
||
| 917 | * @author Dmitry (dio) Levashov |
||
| 918 | **/ |
||
| 919 | View Code Duplication | protected function ls($args) { |
|
| 928 | |||
| 929 | /** |
||
| 930 | * Return subdirs for required directory |
||
| 931 | * |
||
| 932 | * @param array command arguments |
||
| 933 | * @return array |
||
| 934 | * @author Dmitry (dio) Levashov |
||
| 935 | **/ |
||
| 936 | View Code Duplication | protected function tree($args) { |
|
| 946 | |||
| 947 | /** |
||
| 948 | * Return parents dir for required directory |
||
| 949 | * |
||
| 950 | * @param array command arguments |
||
| 951 | * @return array |
||
| 952 | * @author Dmitry (dio) Levashov |
||
| 953 | **/ |
||
| 954 | View Code Duplication | protected function parents($args) { |
|
| 964 | |||
| 965 | /** |
||
| 966 | * Return new created thumbnails list |
||
| 967 | * |
||
| 968 | * @param array command arguments |
||
| 969 | * @return array |
||
| 970 | * @author Dmitry (dio) Levashov |
||
| 971 | **/ |
||
| 972 | protected function tmb($args) { |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Required to output file in browser when volume URL is not set |
||
| 988 | * Return array contains opened file pointer, root itself and required headers |
||
| 989 | * |
||
| 990 | * @param array command arguments |
||
| 991 | * @return array |
||
| 992 | * @author Dmitry (dio) Levashov |
||
| 993 | **/ |
||
| 994 | protected function file($args) { |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Count total files size |
||
| 1071 | * |
||
| 1072 | * @param array command arguments |
||
| 1073 | * @return array |
||
| 1074 | * @author Dmitry (dio) Levashov |
||
| 1075 | **/ |
||
| 1076 | protected function size($args) { |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Create directory |
||
| 1093 | * |
||
| 1094 | * @param array command arguments |
||
| 1095 | * @return array |
||
| 1096 | * @author Dmitry (dio) Levashov |
||
| 1097 | **/ |
||
| 1098 | View Code Duplication | protected function mkdir($args) { |
|
| 1110 | |||
| 1111 | /** |
||
| 1112 | * Create empty file |
||
| 1113 | * |
||
| 1114 | * @param array command arguments |
||
| 1115 | * @return array |
||
| 1116 | * @author Dmitry (dio) Levashov |
||
| 1117 | **/ |
||
| 1118 | View Code Duplication | protected function mkfile($args) { |
|
| 1130 | |||
| 1131 | /** |
||
| 1132 | * Rename file |
||
| 1133 | * |
||
| 1134 | * @param array $args |
||
| 1135 | * @return array |
||
| 1136 | * @author Dmitry (dio) Levashov |
||
| 1137 | **/ |
||
| 1138 | protected function rename($args) { |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Duplicate file - create copy with "copy %d" suffix |
||
| 1155 | * |
||
| 1156 | * @param array $args command arguments |
||
| 1157 | * @return array |
||
| 1158 | * @author Dmitry (dio) Levashov |
||
| 1159 | **/ |
||
| 1160 | protected function duplicate($args) { |
||
| 1182 | |||
| 1183 | /** |
||
| 1184 | * Remove dirs/files |
||
| 1185 | * |
||
| 1186 | * @param array command arguments |
||
| 1187 | * @return array |
||
| 1188 | * @author Dmitry (dio) Levashov |
||
| 1189 | **/ |
||
| 1190 | protected function rm($args) { |
||
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Get remote contents |
||
| 1210 | * |
||
| 1211 | * @param string $url target url |
||
| 1212 | * @param int $timeout timeout (sec) |
||
| 1213 | * @param int $redirect_max redirect max count |
||
| 1214 | * @param string $ua |
||
| 1215 | * @param resource $fp |
||
| 1216 | * @return string or bool(false) |
||
| 1217 | * @retval string contents |
||
| 1218 | * @retval false error |
||
| 1219 | * @author Naoki Sawada |
||
| 1220 | **/ |
||
| 1221 | protected function get_remote_contents( &$url, $timeout = 30, $redirect_max = 5, $ua = 'Mozilla/5.0', $fp = null ) { |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Get remote contents with cURL |
||
| 1228 | * |
||
| 1229 | * @param string $url target url |
||
| 1230 | * @param int $timeout timeout (sec) |
||
| 1231 | * @param int $redirect_max redirect max count |
||
| 1232 | * @param string $ua |
||
| 1233 | * @param resource $outfp |
||
| 1234 | * @return string or bool(false) |
||
| 1235 | * @retval string contents |
||
| 1236 | * @retval false error |
||
| 1237 | * @author Naoki Sawada |
||
| 1238 | **/ |
||
| 1239 | protected function curl_get_contents( &$url, $timeout, $redirect_max, $ua, $outfp ){ |
||
| 1260 | |||
| 1261 | /** |
||
| 1262 | * Get remote contents with fsockopen() |
||
| 1263 | * |
||
| 1264 | * @param string $url url |
||
| 1265 | * @param int $timeout timeout (sec) |
||
| 1266 | * @param int $redirect_max redirect max count |
||
| 1267 | * @param string $ua |
||
| 1268 | * @param resource $outfp |
||
| 1269 | * @return string or bool(false) |
||
| 1270 | * @retval string contents |
||
| 1271 | * @retval false error |
||
| 1272 | * @author Naoki Sawada |
||
| 1273 | */ |
||
| 1274 | protected function fsock_get_contents( &$url, $timeout, $redirect_max, $ua, $outfp ) { |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Parse Data URI scheme |
||
| 1401 | * |
||
| 1402 | * @param string $str |
||
| 1403 | * @param array $extTable |
||
| 1404 | * @return array |
||
| 1405 | * @author Naoki Sawada |
||
| 1406 | */ |
||
| 1407 | protected function parse_data_scheme( $str, $extTable ) { |
||
| 1419 | |||
| 1420 | /** |
||
| 1421 | * Detect file type extension by local path |
||
| 1422 | * |
||
| 1423 | * @param string $path Local path |
||
| 1424 | * @return string file type extension with dot |
||
| 1425 | * @author Naoki Sawada |
||
| 1426 | */ |
||
| 1427 | protected function detectFileExtension($path) { |
||
| 1479 | |||
| 1480 | /** |
||
| 1481 | * Get temporary dirctroy path |
||
| 1482 | * |
||
| 1483 | * @param string $volumeTempPath |
||
| 1484 | * @return string |
||
| 1485 | * @author Naoki Sawada |
||
| 1486 | */ |
||
| 1487 | private function getTempDir($volumeTempPath = null) { |
||
| 1514 | |||
| 1515 | /** |
||
| 1516 | * chmod |
||
| 1517 | * |
||
| 1518 | * @param array command arguments |
||
| 1519 | * @return array |
||
| 1520 | * @author David Bartle |
||
| 1521 | **/ |
||
| 1522 | protected function chmod($args) { |
||
| 1559 | |||
| 1560 | /** |
||
| 1561 | * Check chunked upload files |
||
| 1562 | * |
||
| 1563 | * @param string $tmpname uploaded temporary file path |
||
| 1564 | * @param string $chunk uploaded chunk file name |
||
| 1565 | * @param string $cid uploaded chunked file id |
||
| 1566 | * @param string $tempDir temporary dirctroy path |
||
| 1567 | * @return array (string JoinedTemporaryFilePath, string FileName) or (empty, empty) |
||
| 1568 | * @author Naoki Sawada |
||
| 1569 | */ |
||
| 1570 | private function checkChunkedFile($tmpname, $chunk, $cid, $tempDir, $volume = null) { |
||
| 1693 | |||
| 1694 | /** |
||
| 1695 | * Save uploaded files |
||
| 1696 | * |
||
| 1697 | * @param array |
||
| 1698 | * @return array |
||
| 1699 | * @author Dmitry (dio) Levashov |
||
| 1700 | **/ |
||
| 1701 | protected function upload($args) { |
||
| 1959 | |||
| 1960 | /** |
||
| 1961 | * Copy/move files into new destination |
||
| 1962 | * |
||
| 1963 | * @param array command arguments |
||
| 1964 | * @return array |
||
| 1965 | * @author Dmitry (dio) Levashov |
||
| 1966 | **/ |
||
| 1967 | protected function paste($args) { |
||
| 2019 | |||
| 2020 | /** |
||
| 2021 | * Return file content |
||
| 2022 | * |
||
| 2023 | * @param array $args command arguments |
||
| 2024 | * @return array |
||
| 2025 | * @author Dmitry (dio) Levashov |
||
| 2026 | **/ |
||
| 2027 | protected function get($args) { |
||
| 2062 | |||
| 2063 | /** |
||
| 2064 | * Save content into text file |
||
| 2065 | * |
||
| 2066 | * @return array |
||
| 2067 | * @author Dmitry (dio) Levashov |
||
| 2068 | **/ |
||
| 2069 | protected function put($args) { |
||
| 2083 | |||
| 2084 | /** |
||
| 2085 | * Extract files from archive |
||
| 2086 | * |
||
| 2087 | * @param array $args command arguments |
||
| 2088 | * @return array |
||
| 2089 | * @author Dmitry (dio) Levashov, |
||
| 2090 | * @author Alexey Sukhotin |
||
| 2091 | **/ |
||
| 2092 | protected function extract($args) { |
||
| 2107 | |||
| 2108 | /** |
||
| 2109 | * Create archive |
||
| 2110 | * |
||
| 2111 | * @param array $args command arguments |
||
| 2112 | * @return array |
||
| 2113 | * @author Dmitry (dio) Levashov, |
||
| 2114 | * @author Alexey Sukhotin |
||
| 2115 | **/ |
||
| 2116 | protected function archive($args) { |
||
| 2129 | |||
| 2130 | /** |
||
| 2131 | * Search files |
||
| 2132 | * |
||
| 2133 | * @param array $args command arguments |
||
| 2134 | * @return array |
||
| 2135 | * @author Dmitry Levashov |
||
| 2136 | **/ |
||
| 2137 | protected function search($args) { |
||
| 2154 | |||
| 2155 | /** |
||
| 2156 | * Return file info (used by client "places" ui) |
||
| 2157 | * |
||
| 2158 | * @param array $args command arguments |
||
| 2159 | * @return array |
||
| 2160 | * @author Dmitry Levashov |
||
| 2161 | **/ |
||
| 2162 | protected function info($args) { |
||
| 2215 | |||
| 2216 | /** |
||
| 2217 | * Return image dimmensions |
||
| 2218 | * |
||
| 2219 | * @param array $args command arguments |
||
| 2220 | * @return array |
||
| 2221 | * @author Dmitry (dio) Levashov |
||
| 2222 | **/ |
||
| 2223 | protected function dim($args) { |
||
| 2232 | |||
| 2233 | /** |
||
| 2234 | * Resize image |
||
| 2235 | * |
||
| 2236 | * @param array command arguments |
||
| 2237 | * @return array |
||
| 2238 | * @author Dmitry (dio) Levashov |
||
| 2239 | * @author Alexey Sukhotin |
||
| 2240 | **/ |
||
| 2241 | protected function resize($args) { |
||
| 2261 | |||
| 2262 | /** |
||
| 2263 | * Return content URL |
||
| 2264 | * |
||
| 2265 | * @param array $args command arguments |
||
| 2266 | * @return array |
||
| 2267 | * @author Naoki Sawada |
||
| 2268 | **/ |
||
| 2269 | protected function url($args) { |
||
| 2278 | |||
| 2279 | /** |
||
| 2280 | * Output callback result with JavaScript that control elFinder |
||
| 2281 | * or HTTP redirect to callbackWindowURL |
||
| 2282 | * |
||
| 2283 | * @param array command arguments |
||
| 2284 | * @author Naoki Sawada |
||
| 2285 | */ |
||
| 2286 | protected function callback($args) { |
||
| 2352 | |||
| 2353 | /***************************************************************************/ |
||
| 2354 | /* utils */ |
||
| 2355 | /***************************************************************************/ |
||
| 2356 | |||
| 2357 | /** |
||
| 2358 | * Return root - file's owner |
||
| 2359 | * |
||
| 2360 | * @param string file hash |
||
| 2361 | * @return elFinderStorageDriver |
||
| 2362 | * @author Dmitry (dio) Levashov |
||
| 2363 | **/ |
||
| 2364 | protected function volume($hash) { |
||
| 2372 | |||
| 2373 | /** |
||
| 2374 | * Return files info array |
||
| 2375 | * |
||
| 2376 | * @param array $data one file info or files info |
||
| 2377 | * @return array |
||
| 2378 | * @author Dmitry (dio) Levashov |
||
| 2379 | **/ |
||
| 2380 | protected function toArray($data) { |
||
| 2383 | |||
| 2384 | /** |
||
| 2385 | * Return fils hashes list |
||
| 2386 | * |
||
| 2387 | * @param array $files files info |
||
| 2388 | * @return array |
||
| 2389 | * @author Dmitry (dio) Levashov |
||
| 2390 | **/ |
||
| 2391 | protected function hashes($files) { |
||
| 2398 | |||
| 2399 | /** |
||
| 2400 | * Remove from files list hidden files and files with required mime types |
||
| 2401 | * |
||
| 2402 | * @param array $files files info |
||
| 2403 | * @return array |
||
| 2404 | * @author Dmitry (dio) Levashov |
||
| 2405 | **/ |
||
| 2406 | protected function filter($files) { |
||
| 2414 | |||
| 2415 | protected function utime() { |
||
| 2419 | |||
| 2420 | |||
| 2421 | /***************************************************************************/ |
||
| 2422 | /* static utils */ |
||
| 2423 | /***************************************************************************/ |
||
| 2424 | |||
| 2425 | /** |
||
| 2426 | * Return Is Animation Gif |
||
| 2427 | * |
||
| 2428 | * @param string $path server local path of target image |
||
| 2429 | * @return bool |
||
| 2430 | */ |
||
| 2431 | public static function isAnimationGif($path) { |
||
| 2473 | |||
| 2474 | /** |
||
| 2475 | * Return Is seekable stream resource |
||
| 2476 | * |
||
| 2477 | * @param resource $resource |
||
| 2478 | * @return bool |
||
| 2479 | */ |
||
| 2480 | public static function isSeekableStream($resource) { |
||
| 2484 | |||
| 2485 | /** |
||
| 2486 | * serialize and base64_encode of session data (If needed) |
||
| 2487 | * |
||
| 2488 | * @param mixed $var target variable |
||
| 2489 | * @author Naoki Sawada |
||
| 2490 | */ |
||
| 2491 | public static function sessionDataEncode($var) { |
||
| 2497 | |||
| 2498 | /** |
||
| 2499 | * base64_decode and unserialize of session data (If needed) |
||
| 2500 | * |
||
| 2501 | * @param mixed $var target variable |
||
| 2502 | * @param bool $checkIs data type for check (array|string|object|int) |
||
| 2503 | * @author Naoki Sawada |
||
| 2504 | */ |
||
| 2505 | public static function sessionDataDecode(&$var, $checkIs = null) { |
||
| 2534 | } // END class |
||
| 2535 |
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.