protected function open($args)
{
$target = $args['target'];
$init = !empty($args['init']);
$tree = !empty($args['tree']);
$volume = $this->volume($target);
$cwd = $volume ? $volume->dir($target, true) : false;
$hash = $init ? 'default folder' : '#' . $target;
// on init request we can get invalid dir hash -
// dir which can not be opened now, but remembered by client,
// so open default dir
if ((!$cwd || !$cwd['read']) && $init) {
$volume = $this->default;
$cwd = $volume->dir($volume->defaultPath(), true);
}
if (!$cwd) {
return array('error' => $this->error(self::ERROR_OPEN, $hash, self::ERROR_DIR_NOT_FOUND));
}
if (!$cwd['read']) {
return array('error' => $this->error(self::ERROR_OPEN, $hash, self::ERROR_PERM_DENIED));
}
$files = array();
// get folders trees
if ($args['tree']) {
foreach ($this->volumes as $id => $v) {
if (($tree = $v->tree('', 0, $cwd['hash'])) != false) {
$files = array_merge($files, $tree);
}
}
}
// get current working directory files list and add to $files if not exists in it
if (($ls = $volume->scandir($cwd['hash'])) === false) {
return array('error' => $this->error(self::ERROR_OPEN, $cwd['name'], $volume->error()));
}
foreach ($ls as $file) {
if (!in_array($file, $files)) {
$files[] = $file;
}
}
$result = array('cwd' => $cwd, 'options' => $volume->options($cwd['hash']), 'files' => $files);
if (!empty($args['init'])) {
$result['api'] = $this->version;
$result['uplMaxSize'] = ini_get('upload_max_filesize');
$result['netDrivers'] = array_keys(self::$netDrivers);
}
return $result;
}