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 @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 | // try session start | restart |
||
| 270 | try { |
||
| 271 | session_start(); |
||
| 272 | } catch (Exception $e) {} |
||
| 273 | |||
| 274 | if (isset($opts['sessionUseCmds']) && is_array($opts['sessionUseCmds'])) { |
||
| 275 | $sessionUseCmds = array_merge($sessionUseCmds, $opts['sessionUseCmds']); |
||
| 276 | } |
||
| 277 | |||
| 278 | // set self::$volumesCnt by HTTP header "X-elFinder-VolumesCntStart" |
||
| 279 | if (isset($_SERVER['HTTP_X_ELFINDER_VOLUMESCNTSTART']) && ($volumesCntStart = intval($_SERVER['HTTP_X_ELFINDER_VOLUMESCNTSTART']))) { |
||
| 280 | self::$volumesCnt = $volumesCntStart; |
||
| 281 | } |
||
| 282 | |||
| 283 | $this->time = $this->utime(); |
||
| 284 | $this->debug = (isset($opts['debug']) && $opts['debug'] ? true : false); |
||
| 285 | $this->sessionCloseEarlier = isset($opts['sessionCloseEarlier'])? (bool)$opts['sessionCloseEarlier'] : true; |
||
| 286 | $this->sessionUseCmds = array_flip($sessionUseCmds); |
||
| 287 | $this->timeout = (isset($opts['timeout']) ? $opts['timeout'] : 0); |
||
| 288 | $this->uploadTempPath = (isset($opts['uploadTempPath']) ? $opts['uploadTempPath'] : ''); |
||
| 289 | $this->netVolumesSessionKey = !empty($opts['netVolumesSessionKey'])? $opts['netVolumesSessionKey'] : 'elFinderNetVolumes'; |
||
| 290 | $this->callbackWindowURL = (isset($opts['callbackWindowURL']) ? $opts['callbackWindowURL'] : ''); |
||
| 291 | self::$sessionCacheKey = !empty($opts['sessionCacheKey']) ? $opts['sessionCacheKey'] : 'elFinderCaches'; |
||
| 292 | |||
| 293 | // check session cache |
||
| 294 | $_optsMD5 = md5(json_encode($opts['roots'])); |
||
| 295 | if (! isset($_SESSION[self::$sessionCacheKey]) || $_SESSION[self::$sessionCacheKey]['_optsMD5'] !== $_optsMD5) { |
||
| 296 | $_SESSION[self::$sessionCacheKey] = array( |
||
| 297 | '_optsMD5' => $_optsMD5 |
||
| 298 | ); |
||
| 299 | } |
||
| 300 | self::$base64encodeSessionData = !empty($opts['base64encodeSessionData']); |
||
| 301 | |||
| 302 | // setlocale and global locale regists to elFinder::locale |
||
| 303 | self::$locale = !empty($opts['locale']) ? $opts['locale'] : 'en_US.UTF-8'; |
||
| 304 | if (false === @setlocale(LC_ALL, self::$locale)) { |
||
| 305 | self::$locale = setlocale(LC_ALL, ''); |
||
| 306 | } |
||
| 307 | |||
| 308 | // bind events listeners |
||
| 309 | if (!empty($opts['bind']) && is_array($opts['bind'])) { |
||
| 310 | $_req = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET; |
||
| 311 | $_reqCmd = isset($_req['cmd']) ? $_req['cmd'] : ''; |
||
| 312 | foreach ($opts['bind'] as $cmd => $handlers) { |
||
| 313 | $doRegist = (strpos($cmd, '*') !== false); |
||
| 314 | if (! $doRegist) { |
||
| 315 | $_getcmd = create_function('$cmd', 'list($ret) = explode(\'.\', $cmd);return trim($ret);'); |
||
| 316 | $doRegist = ($_reqCmd && in_array($_reqCmd, array_map($_getcmd, explode(' ', $cmd)))); |
||
| 317 | } |
||
| 318 | if ($doRegist) { |
||
| 319 | if (! is_array($handlers) || is_object($handlers[0])) { |
||
| 320 | $handlers = array($handlers); |
||
| 321 | } |
||
| 322 | foreach($handlers as $handler) { |
||
| 323 | if ($handler) { |
||
| 324 | if (is_string($handler) && strpos($handler, '.')) { |
||
| 325 | list($_domain, $_name, $_method) = array_pad(explode('.', $handler), 3, ''); |
||
| 326 | if (strcasecmp($_domain, 'plugin') === 0) { |
||
| 327 | if ($plugin = $this->getPluginInstance($_name, isset($opts['plugin'][$_name])? $opts['plugin'][$_name] : array()) |
||
| 328 | and method_exists($plugin, $_method)) { |
||
| 329 | $this->bind($cmd, array($plugin, $_method)); |
||
| 330 | } |
||
| 331 | } |
||
| 332 | } else { |
||
| 333 | $this->bind($cmd, $handler); |
||
| 334 | } |
||
| 335 | } |
||
| 336 | } |
||
| 337 | } |
||
| 338 | } |
||
| 339 | } |
||
| 340 | |||
| 341 | if (!isset($opts['roots']) || !is_array($opts['roots'])) { |
||
| 342 | $opts['roots'] = array(); |
||
| 343 | } |
||
| 344 | |||
| 345 | // check for net volumes stored in session |
||
| 346 | foreach ($this->getNetVolumes() as $key => $root) { |
||
| 347 | $opts['roots'][$key] = $root; |
||
| 348 | } |
||
| 349 | |||
| 350 | // "mount" volumes |
||
| 351 | foreach ($opts['roots'] as $i => $o) { |
||
| 352 | $class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : ''); |
||
| 353 | |||
| 354 | if (class_exists($class)) { |
||
| 355 | $volume = new $class(); |
||
| 356 | |||
| 357 | try { |
||
| 358 | if ($volume->mount($o)) { |
||
| 359 | // unique volume id (ends on "_") - used as prefix to files hash |
||
| 360 | $id = $volume->id(); |
||
| 361 | |||
| 362 | $this->volumes[$id] = $volume; |
||
| 363 | if ((!$this->default || $volume->root() !== $volume->defaultPath()) && $volume->isReadable()) { |
||
| 364 | $this->default = $this->volumes[$id]; |
||
| 365 | } |
||
| 366 | } else { |
||
| 367 | $this->removeNetVolume($i); |
||
| 368 | $this->mountErrors[] = 'Driver "'.$class.'" : '.implode(' ', $volume->error()); |
||
| 369 | } |
||
| 370 | } catch (Exception $e) { |
||
| 371 | $this->removeNetVolume($i); |
||
| 372 | $this->mountErrors[] = 'Driver "'.$class.'" : '.$e->getMessage(); |
||
| 373 | } |
||
| 374 | } else { |
||
| 375 | $this->mountErrors[] = 'Driver "'.$class.'" does not exists'; |
||
| 376 | } |
||
| 377 | } |
||
| 378 | |||
| 379 | // if at least one readable volume - ii desu >_< |
||
| 380 | $this->loaded = !empty($this->default); |
||
| 381 | } |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Return true if fm init correctly |
||
| 385 | * |
||
| 386 | * @return bool |
||
| 387 | * @author Dmitry (dio) Levashov |
||
| 388 | **/ |
||
| 389 | public function loaded() { |
||
| 390 | return $this->loaded; |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Return version (api) number |
||
| 395 | * |
||
| 396 | * @return string |
||
| 397 | * @author Dmitry (dio) Levashov |
||
| 398 | **/ |
||
| 399 | public function version() { |
||
| 400 | return $this->version; |
||
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Add handler to elFinder command |
||
| 405 | * |
||
| 406 | * @param string command name |
||
| 407 | * @param string|array callback name or array(object, method) |
||
| 408 | * @return elFinder |
||
| 409 | * @author Dmitry (dio) Levashov |
||
| 410 | **/ |
||
| 411 | public function bind($cmd, $handler) { |
||
| 412 | $allCmds = array_keys($this->commands); |
||
| 413 | $cmds = array(); |
||
| 414 | foreach(explode(' ', $cmd) as $_cmd) { |
||
| 415 | if ($_cmd !== '') { |
||
| 416 | if ($all = strpos($_cmd, '*') !== false) { |
||
| 417 | list(, $sub) = array_pad(explode('.', $_cmd), 2, ''); |
||
| 418 | if ($sub) { |
||
| 419 | $sub = str_replace('\'', '\\\'', $sub); |
||
| 420 | $addSub = create_function('$cmd', 'return $cmd . \'.\' . trim(\'' . $sub . '\');'); |
||
| 421 | $cmds = array_merge($cmds, array_map($addSub, $allCmds)); |
||
| 422 | } else { |
||
| 423 | $cmds = array_merge($cmds, $allCmds); |
||
| 424 | } |
||
| 425 | } else { |
||
| 426 | $cmds[] = $_cmd; |
||
| 427 | } |
||
| 428 | } |
||
| 429 | } |
||
| 430 | $cmds = array_unique($cmds); |
||
| 431 | |||
| 432 | foreach ($cmds as $cmd) { |
||
| 433 | if (!isset($this->listeners[$cmd])) { |
||
| 434 | $this->listeners[$cmd] = array(); |
||
| 435 | } |
||
| 436 | |||
| 437 | if (is_callable($handler)) { |
||
| 438 | $this->listeners[$cmd][] = $handler; |
||
| 439 | } |
||
| 440 | } |
||
| 441 | |||
| 442 | return $this; |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Remove event (command exec) handler |
||
| 447 | * |
||
| 448 | * @param string command name |
||
| 449 | * @param string|array callback name or array(object, method) |
||
| 450 | * @return elFinder |
||
| 451 | * @author Dmitry (dio) Levashov |
||
| 452 | **/ |
||
| 453 | public function unbind($cmd, $handler) { |
||
| 454 | if (!empty($this->listeners[$cmd])) { |
||
| 455 | foreach ($this->listeners[$cmd] as $i => $h) { |
||
| 456 | if ($h === $handler) { |
||
| 457 | unset($this->listeners[$cmd][$i]); |
||
| 458 | return $this; |
||
| 459 | } |
||
| 460 | } |
||
| 461 | } |
||
| 462 | return $this; |
||
| 463 | } |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Return true if command exists |
||
| 467 | * |
||
| 468 | * @param string command name |
||
| 469 | * @return bool |
||
| 470 | * @author Dmitry (dio) Levashov |
||
| 471 | **/ |
||
| 472 | public function commandExists($cmd) { |
||
| 473 | return $this->loaded && isset($this->commands[$cmd]) && method_exists($this, $cmd); |
||
| 474 | } |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Return root - file's owner (public func of volume()) |
||
| 478 | * |
||
| 479 | * @param string file hash |
||
| 480 | * @return elFinderStorageDriver |
||
| 481 | * @author Naoki Sawada |
||
| 482 | */ |
||
| 483 | public function getVolume($hash) { |
||
| 484 | return $this->volume($hash); |
||
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Return command required arguments info |
||
| 489 | * |
||
| 490 | * @param string command name |
||
| 491 | * @return array |
||
| 492 | * @author Dmitry (dio) Levashov |
||
| 493 | **/ |
||
| 494 | public function commandArgsList($cmd) { |
||
| 495 | return $this->commandExists($cmd) ? $this->commands[$cmd] : array(); |
||
| 496 | } |
||
| 497 | |||
| 498 | private function session_expires() { |
||
| 499 | |||
| 500 | if (!isset($_SESSION[self::$sessionCacheKey . ':LAST_ACTIVITY'])) { |
||
| 501 | $_SESSION[self::$sessionCacheKey . ':LAST_ACTIVITY'] = time(); |
||
| 502 | return false; |
||
| 503 | } |
||
| 504 | |||
| 505 | if ( ($this->timeout > 0) && (time() - $_SESSION[self::$sessionCacheKey . ':LAST_ACTIVITY'] > $this->timeout) ) { |
||
| 506 | return true; |
||
| 507 | } |
||
| 508 | |||
| 509 | $_SESSION[self::$sessionCacheKey . ':LAST_ACTIVITY'] = time(); |
||
| 510 | return false; |
||
| 511 | } |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Exec command and return result |
||
| 515 | * |
||
| 516 | * @param string $cmd command name |
||
| 517 | * @param array $args command arguments |
||
| 518 | * @return array |
||
| 519 | * @author Dmitry (dio) Levashov |
||
| 520 | **/ |
||
| 521 | public function exec($cmd, $args) { |
||
| 522 | |||
| 523 | if (!$this->loaded) { |
||
| 524 | return array('error' => $this->error(self::ERROR_CONF, self::ERROR_CONF_NO_VOL)); |
||
| 525 | } |
||
| 526 | |||
| 527 | if ($this->session_expires()) { |
||
| 528 | return array('error' => $this->error(self::ERROR_SESSION_EXPIRES)); |
||
| 529 | } |
||
| 530 | |||
| 531 | if (!$this->commandExists($cmd)) { |
||
| 532 | return array('error' => $this->error(self::ERROR_UNKNOWN_CMD)); |
||
| 533 | } |
||
| 534 | |||
| 535 | if (!empty($args['mimes']) && is_array($args['mimes'])) { |
||
| 536 | foreach ($this->volumes as $id => $v) { |
||
| 537 | $this->volumes[$id]->setMimesFilter($args['mimes']); |
||
| 538 | } |
||
| 539 | } |
||
| 540 | |||
| 541 | // call pre handlers for this command |
||
| 542 | $args['sessionCloseEarlier'] = isset($this->sessionUseCmds[$cmd])? false : $this->sessionCloseEarlier; |
||
| 543 | if (!empty($this->listeners[$cmd.'.pre'])) { |
||
| 544 | $volume = isset($args['target'])? $this->volume($args['target']) : false; |
||
| 545 | View Code Duplication | foreach ($this->listeners[$cmd.'.pre'] as $handler) { |
|
| 546 | call_user_func_array($handler, array($cmd, &$args, $this, $volume)); |
||
| 547 | } |
||
| 548 | } |
||
| 549 | |||
| 550 | // unlock session data for multiple access |
||
| 551 | $this->sessionCloseEarlier && $args['sessionCloseEarlier'] && session_id() && session_write_close(); |
||
| 552 | |||
| 553 | if (substr(PHP_OS,0,3) === 'WIN') { |
||
| 554 | // set time out |
||
| 555 | if (($_max_execution_time = ini_get('max_execution_time')) && $_max_execution_time < 300) { |
||
| 556 | @set_time_limit(300); |
||
| 557 | } |
||
| 558 | } |
||
| 559 | |||
| 560 | $result = $this->$cmd($args); |
||
| 561 | |||
| 562 | if (isset($result['removed'])) { |
||
| 563 | foreach ($this->volumes as $volume) { |
||
| 564 | $result['removed'] = array_merge($result['removed'], $volume->removed()); |
||
| 565 | $volume->resetRemoved(); |
||
| 566 | } |
||
| 567 | } |
||
| 568 | |||
| 569 | // call handlers for this command |
||
| 570 | if (!empty($this->listeners[$cmd])) { |
||
| 571 | foreach ($this->listeners[$cmd] as $handler) { |
||
| 572 | if (call_user_func_array($handler,array($cmd,&$result,$args,$this))) { |
||
| 573 | // handler return true to force sync client after command completed |
||
| 574 | $result['sync'] = true; |
||
| 575 | } |
||
| 576 | } |
||
| 577 | } |
||
| 578 | |||
| 579 | // replace removed files info with removed files hashes |
||
| 580 | if (!empty($result['removed'])) { |
||
| 581 | $removed = array(); |
||
| 582 | foreach ($result['removed'] as $file) { |
||
| 583 | $removed[] = $file['hash']; |
||
| 584 | } |
||
| 585 | $result['removed'] = array_unique($removed); |
||
| 586 | } |
||
| 587 | // remove hidden files and filter files by mimetypes |
||
| 588 | if (!empty($result['added'])) { |
||
| 589 | $result['added'] = $this->filter($result['added']); |
||
| 590 | } |
||
| 591 | // remove hidden files and filter files by mimetypes |
||
| 592 | if (!empty($result['changed'])) { |
||
| 593 | $result['changed'] = $this->filter($result['changed']); |
||
| 594 | } |
||
| 595 | |||
| 596 | if ($this->debug || !empty($args['debug'])) { |
||
| 597 | $result['debug'] = array( |
||
| 598 | 'connector' => 'php', |
||
| 599 | 'phpver' => PHP_VERSION, |
||
| 600 | 'time' => $this->utime() - $this->time, |
||
| 601 | 'memory' => (function_exists('memory_get_peak_usage') ? ceil(memory_get_peak_usage()/1024).'Kb / ' : '').ceil(memory_get_usage()/1024).'Kb / '.ini_get('memory_limit'), |
||
| 602 | 'upload' => $this->uploadDebug, |
||
| 603 | 'volumes' => array(), |
||
| 604 | 'mountErrors' => $this->mountErrors |
||
| 605 | ); |
||
| 606 | |||
| 607 | foreach ($this->volumes as $id => $volume) { |
||
| 608 | $result['debug']['volumes'][] = $volume->debug(); |
||
| 609 | } |
||
| 610 | } |
||
| 611 | |||
| 612 | foreach ($this->volumes as $volume) { |
||
| 613 | $volume->umount(); |
||
| 614 | } |
||
| 615 | |||
| 616 | if (!empty($result['callback'])) { |
||
| 617 | $result['callback']['json'] = json_encode($result); |
||
| 618 | $this->callback($result['callback']); |
||
| 619 | } else { |
||
| 620 | return $result; |
||
| 621 | } |
||
| 622 | } |
||
| 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) { |
||
| 725 | // try session restart |
||
| 726 | try { |
||
| 727 | session_start(); |
||
| 728 | } catch (Exception $e) {} |
||
| 729 | |||
| 730 | $options = array(); |
||
| 731 | $protocol = $args['protocol']; |
||
| 732 | |||
| 733 | if ($protocol === 'netunmount') { |
||
| 804 | |||
| 805 | /** |
||
| 806 | * "Open" directory |
||
| 807 | * Return array with following elements |
||
| 808 | * - cwd - opened dir info |
||
| 809 | * - files - opened dir content [and dirs tree if $args[tree]] |
||
| 810 | * - api - api version (if $args[init]) |
||
| 811 | * - uplMaxSize - if $args[init] |
||
| 812 | * - error - on failed |
||
| 813 | * |
||
| 814 | * @param array command arguments |
||
| 815 | * @return array |
||
| 816 | * @author Dmitry (dio) Levashov |
||
| 817 | **/ |
||
| 818 | protected function open($args) { |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Return dir files names list |
||
| 919 | * |
||
| 920 | * @param array command arguments |
||
| 921 | * @return array |
||
| 922 | * @author Dmitry (dio) Levashov |
||
| 923 | **/ |
||
| 924 | View Code Duplication | protected function ls($args) { |
|
| 933 | |||
| 934 | /** |
||
| 935 | * Return subdirs for required directory |
||
| 936 | * |
||
| 937 | * @param array command arguments |
||
| 938 | * @return array |
||
| 939 | * @author Dmitry (dio) Levashov |
||
| 940 | **/ |
||
| 941 | View Code Duplication | protected function tree($args) { |
|
| 951 | |||
| 952 | /** |
||
| 953 | * Return parents dir for required directory |
||
| 954 | * |
||
| 955 | * @param array command arguments |
||
| 956 | * @return array |
||
| 957 | * @author Dmitry (dio) Levashov |
||
| 958 | **/ |
||
| 959 | View Code Duplication | protected function parents($args) { |
|
| 969 | |||
| 970 | /** |
||
| 971 | * Return new created thumbnails list |
||
| 972 | * |
||
| 973 | * @param array command arguments |
||
| 974 | * @return array |
||
| 975 | * @author Dmitry (dio) Levashov |
||
| 976 | **/ |
||
| 977 | protected function tmb($args) { |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Required to output file in browser when volume URL is not set |
||
| 993 | * Return array contains opened file pointer, root itself and required headers |
||
| 994 | * |
||
| 995 | * @param array command arguments |
||
| 996 | * @return array |
||
| 997 | * @author Dmitry (dio) Levashov |
||
| 998 | **/ |
||
| 999 | protected function file($args) { |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Count total files size |
||
| 1076 | * |
||
| 1077 | * @param array command arguments |
||
| 1078 | * @return array |
||
| 1079 | * @author Dmitry (dio) Levashov |
||
| 1080 | **/ |
||
| 1081 | protected function size($args) { |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Create directory |
||
| 1098 | * |
||
| 1099 | * @param array command arguments |
||
| 1100 | * @return array |
||
| 1101 | * @author Dmitry (dio) Levashov |
||
| 1102 | **/ |
||
| 1103 | View Code Duplication | protected function mkdir($args) { |
|
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Create empty file |
||
| 1118 | * |
||
| 1119 | * @param array command arguments |
||
| 1120 | * @return array |
||
| 1121 | * @author Dmitry (dio) Levashov |
||
| 1122 | **/ |
||
| 1123 | View Code Duplication | protected function mkfile($args) { |
|
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Rename file |
||
| 1138 | * |
||
| 1139 | * @param array $args |
||
| 1140 | * @return array |
||
| 1141 | * @author Dmitry (dio) Levashov |
||
| 1142 | **/ |
||
| 1143 | protected function rename($args) { |
||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * Duplicate file - create copy with "copy %d" suffix |
||
| 1160 | * |
||
| 1161 | * @param array $args command arguments |
||
| 1162 | * @return array |
||
| 1163 | * @author Dmitry (dio) Levashov |
||
| 1164 | **/ |
||
| 1165 | protected function duplicate($args) { |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Remove dirs/files |
||
| 1190 | * |
||
| 1191 | * @param array command arguments |
||
| 1192 | * @return array |
||
| 1193 | * @author Dmitry (dio) Levashov |
||
| 1194 | **/ |
||
| 1195 | protected function rm($args) { |
||
| 1212 | |||
| 1213 | /** |
||
| 1214 | * Get remote contents |
||
| 1215 | * |
||
| 1216 | * @param string $url target url |
||
| 1217 | * @param int $timeout timeout (sec) |
||
| 1218 | * @param int $redirect_max redirect max count |
||
| 1219 | * @param string $ua |
||
| 1220 | * @param resource $fp |
||
| 1221 | * @return string or bool(false) |
||
| 1222 | * @retval string contents |
||
| 1223 | * @retval false error |
||
| 1224 | * @author Naoki Sawada |
||
| 1225 | **/ |
||
| 1226 | protected function get_remote_contents( &$url, $timeout = 30, $redirect_max = 5, $ua = 'Mozilla/5.0', $fp = null ) { |
||
| 1230 | |||
| 1231 | /** |
||
| 1232 | * Get remote contents with cURL |
||
| 1233 | * |
||
| 1234 | * @param string $url target url |
||
| 1235 | * @param int $timeout timeout (sec) |
||
| 1236 | * @param int $redirect_max redirect max count |
||
| 1237 | * @param string $ua |
||
| 1238 | * @param resource $outfp |
||
| 1239 | * @return string or bool(false) |
||
| 1240 | * @retval string contents |
||
| 1241 | * @retval false error |
||
| 1242 | * @author Naoki Sawada |
||
| 1243 | **/ |
||
| 1244 | protected function curl_get_contents( &$url, $timeout, $redirect_max, $ua, $outfp ){ |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Get remote contents with fsockopen() |
||
| 1268 | * |
||
| 1269 | * @param string $url url |
||
| 1270 | * @param int $timeout timeout (sec) |
||
| 1271 | * @param int $redirect_max redirect max count |
||
| 1272 | * @param string $ua |
||
| 1273 | * @param resource $outfp |
||
| 1274 | * @return string or bool(false) |
||
| 1275 | * @retval string contents |
||
| 1276 | * @retval false error |
||
| 1277 | * @author Naoki Sawada |
||
| 1278 | */ |
||
| 1279 | protected function fsock_get_contents( &$url, $timeout, $redirect_max, $ua, $outfp ) { |
||
| 1403 | |||
| 1404 | /** |
||
| 1405 | * Parse Data URI scheme |
||
| 1406 | * |
||
| 1407 | * @param string $str |
||
| 1408 | * @param array $extTable |
||
| 1409 | * @return array |
||
| 1410 | * @author Naoki Sawada |
||
| 1411 | */ |
||
| 1412 | protected function parse_data_scheme( $str, $extTable ) { |
||
| 1424 | |||
| 1425 | /** |
||
| 1426 | * Detect file type extension by local path |
||
| 1427 | * |
||
| 1428 | * @param string $path Local path |
||
| 1429 | * @return string file type extension with dot |
||
| 1430 | * @author Naoki Sawada |
||
| 1431 | */ |
||
| 1432 | protected function detectFileExtension($path) { |
||
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Get temporary dirctroy path |
||
| 1487 | * |
||
| 1488 | * @param string $volumeTempPath |
||
| 1489 | * @return string |
||
| 1490 | * @author Naoki Sawada |
||
| 1491 | */ |
||
| 1492 | private function getTempDir($volumeTempPath = null) { |
||
| 1519 | |||
| 1520 | /** |
||
| 1521 | * chmod |
||
| 1522 | * |
||
| 1523 | * @param array command arguments |
||
| 1524 | * @return array |
||
| 1525 | * @author David Bartle |
||
| 1526 | **/ |
||
| 1527 | protected function chmod($args) { |
||
| 1564 | |||
| 1565 | /** |
||
| 1566 | * Check chunked upload files |
||
| 1567 | * |
||
| 1568 | * @param string $tmpname uploaded temporary file path |
||
| 1569 | * @param string $chunk uploaded chunk file name |
||
| 1570 | * @param string $cid uploaded chunked file id |
||
| 1571 | * @param string $tempDir temporary dirctroy path |
||
| 1572 | * @return array (string JoinedTemporaryFilePath, string FileName) or (empty, empty) |
||
| 1573 | * @author Naoki Sawada |
||
| 1574 | */ |
||
| 1575 | private function checkChunkedFile($tmpname, $chunk, $cid, $tempDir, $volume = null) { |
||
| 1698 | |||
| 1699 | /** |
||
| 1700 | * Save uploaded files |
||
| 1701 | * |
||
| 1702 | * @param array |
||
| 1703 | * @return array |
||
| 1704 | * @author Dmitry (dio) Levashov |
||
| 1705 | **/ |
||
| 1706 | protected function upload($args) { |
||
| 1964 | |||
| 1965 | /** |
||
| 1966 | * Copy/move files into new destination |
||
| 1967 | * |
||
| 1968 | * @param array command arguments |
||
| 1969 | * @return array |
||
| 1970 | * @author Dmitry (dio) Levashov |
||
| 1971 | **/ |
||
| 1972 | protected function paste($args) { |
||
| 2024 | |||
| 2025 | /** |
||
| 2026 | * Return file content |
||
| 2027 | * |
||
| 2028 | * @param array $args command arguments |
||
| 2029 | * @return array |
||
| 2030 | * @author Dmitry (dio) Levashov |
||
| 2031 | **/ |
||
| 2032 | protected function get($args) { |
||
| 2067 | |||
| 2068 | /** |
||
| 2069 | * Save content into text file |
||
| 2070 | * |
||
| 2071 | * @return array |
||
| 2072 | * @author Dmitry (dio) Levashov |
||
| 2073 | **/ |
||
| 2074 | protected function put($args) { |
||
| 2088 | |||
| 2089 | /** |
||
| 2090 | * Extract files from archive |
||
| 2091 | * |
||
| 2092 | * @param array $args command arguments |
||
| 2093 | * @return array |
||
| 2094 | * @author Dmitry (dio) Levashov, |
||
| 2095 | * @author Alexey Sukhotin |
||
| 2096 | **/ |
||
| 2097 | protected function extract($args) { |
||
| 2112 | |||
| 2113 | /** |
||
| 2114 | * Create archive |
||
| 2115 | * |
||
| 2116 | * @param array $args command arguments |
||
| 2117 | * @return array |
||
| 2118 | * @author Dmitry (dio) Levashov, |
||
| 2119 | * @author Alexey Sukhotin |
||
| 2120 | **/ |
||
| 2121 | protected function archive($args) { |
||
| 2134 | |||
| 2135 | /** |
||
| 2136 | * Search files |
||
| 2137 | * |
||
| 2138 | * @param array $args command arguments |
||
| 2139 | * @return array |
||
| 2140 | * @author Dmitry Levashov |
||
| 2141 | **/ |
||
| 2142 | protected function search($args) { |
||
| 2159 | |||
| 2160 | /** |
||
| 2161 | * Return file info (used by client "places" ui) |
||
| 2162 | * |
||
| 2163 | * @param array $args command arguments |
||
| 2164 | * @return array |
||
| 2165 | * @author Dmitry Levashov |
||
| 2166 | **/ |
||
| 2167 | protected function info($args) { |
||
| 2220 | |||
| 2221 | /** |
||
| 2222 | * Return image dimmensions |
||
| 2223 | * |
||
| 2224 | * @param array $args command arguments |
||
| 2225 | * @return array |
||
| 2226 | * @author Dmitry (dio) Levashov |
||
| 2227 | **/ |
||
| 2228 | protected function dim($args) { |
||
| 2237 | |||
| 2238 | /** |
||
| 2239 | * Resize image |
||
| 2240 | * |
||
| 2241 | * @param array command arguments |
||
| 2242 | * @return array |
||
| 2243 | * @author Dmitry (dio) Levashov |
||
| 2244 | * @author Alexey Sukhotin |
||
| 2245 | **/ |
||
| 2246 | protected function resize($args) { |
||
| 2266 | |||
| 2267 | /** |
||
| 2268 | * Return content URL |
||
| 2269 | * |
||
| 2270 | * @param array $args command arguments |
||
| 2271 | * @return array |
||
| 2272 | * @author Naoki Sawada |
||
| 2273 | **/ |
||
| 2274 | protected function url($args) { |
||
| 2283 | |||
| 2284 | /** |
||
| 2285 | * Output callback result with JavaScript that control elFinder |
||
| 2286 | * or HTTP redirect to callbackWindowURL |
||
| 2287 | * |
||
| 2288 | * @param array command arguments |
||
| 2289 | * @author Naoki Sawada |
||
| 2290 | */ |
||
| 2291 | protected function callback($args) { |
||
| 2357 | |||
| 2358 | /***************************************************************************/ |
||
| 2359 | /* utils */ |
||
| 2360 | /***************************************************************************/ |
||
| 2361 | |||
| 2362 | /** |
||
| 2363 | * Return root - file's owner |
||
| 2364 | * |
||
| 2365 | * @param string file hash |
||
| 2366 | * @return elFinderStorageDriver |
||
| 2367 | * @author Dmitry (dio) Levashov |
||
| 2368 | **/ |
||
| 2369 | protected function volume($hash) { |
||
| 2377 | |||
| 2378 | /** |
||
| 2379 | * Return files info array |
||
| 2380 | * |
||
| 2381 | * @param array $data one file info or files info |
||
| 2382 | * @return array |
||
| 2383 | * @author Dmitry (dio) Levashov |
||
| 2384 | **/ |
||
| 2385 | protected function toArray($data) { |
||
| 2388 | |||
| 2389 | /** |
||
| 2390 | * Return fils hashes list |
||
| 2391 | * |
||
| 2392 | * @param array $files files info |
||
| 2393 | * @return array |
||
| 2394 | * @author Dmitry (dio) Levashov |
||
| 2395 | **/ |
||
| 2396 | protected function hashes($files) { |
||
| 2403 | |||
| 2404 | /** |
||
| 2405 | * Remove from files list hidden files and files with required mime types |
||
| 2406 | * |
||
| 2407 | * @param array $files files info |
||
| 2408 | * @return array |
||
| 2409 | * @author Dmitry (dio) Levashov |
||
| 2410 | **/ |
||
| 2411 | protected function filter($files) { |
||
| 2419 | |||
| 2420 | protected function utime() { |
||
| 2424 | |||
| 2425 | |||
| 2426 | /***************************************************************************/ |
||
| 2427 | /* static utils */ |
||
| 2428 | /***************************************************************************/ |
||
| 2429 | |||
| 2430 | /** |
||
| 2431 | * Return Is Animation Gif |
||
| 2432 | * |
||
| 2433 | * @param string $path server local path of target image |
||
| 2434 | * @return bool |
||
| 2435 | */ |
||
| 2436 | public static function isAnimationGif($path) { |
||
| 2478 | |||
| 2479 | /** |
||
| 2480 | * Return Is seekable stream resource |
||
| 2481 | * |
||
| 2482 | * @param resource $resource |
||
| 2483 | * @return bool |
||
| 2484 | */ |
||
| 2485 | public static function isSeekableStream($resource) { |
||
| 2489 | |||
| 2490 | /** |
||
| 2491 | * serialize and base64_encode of session data (If needed) |
||
| 2492 | * |
||
| 2493 | * @param mixed $var target variable |
||
| 2494 | * @author Naoki Sawada |
||
| 2495 | */ |
||
| 2496 | public static function sessionDataEncode($var) { |
||
| 2502 | |||
| 2503 | /** |
||
| 2504 | * base64_decode and unserialize of session data (If needed) |
||
| 2505 | * |
||
| 2506 | * @param mixed $var target variable |
||
| 2507 | * @param bool $checkIs data type for check (array|string|object|int) |
||
| 2508 | * @author Naoki Sawada |
||
| 2509 | */ |
||
| 2510 | public static function sessionDataDecode(&$var, $checkIs = null) { |
||
| 2539 | } // END class |
||
| 2540 |
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.