protected function updateCache($path, $stat)
{
if (empty($stat) || !is_array($stat)) {
return $this->cache[$path] = array();
}
$stat['hash'] = $this->encode($path);
$root = $path == $this->root;
if ($root) {
$stat['volumeid'] = $this->id;
if ($this->rootName) {
$stat['name'] = $this->rootName;
}
} else {
if (!isset($stat['name']) || !strlen($stat['name'])) {
$stat['name'] = $this->_basename($path);
}
if (empty($stat['phash'])) {
$stat['phash'] = $this->encode($this->_dirname($path));
}
}
// fix name if required
if ($this->options['utf8fix'] && $this->options['utf8patterns'] && $this->options['utf8replace']) {
$stat['name'] = json_decode(str_replace($this->options['utf8patterns'], $this->options['utf8replace'], json_encode($stat['name'])));
}
if (empty($stat['mime'])) {
$stat['mime'] = $this->mimetype($stat['name']);
}
// @todo move dateformat to client
// $stat['date'] = isset($stat['ts'])
// ? $this->formatDate($stat['ts'])
// : 'unknown';
if (!isset($stat['size'])) {
$stat['size'] = 'unknown';
}
$stat['read'] = intval($this->attr($path, 'read', isset($stat['read']) ? !!$stat['read'] : null));
$stat['write'] = intval($this->attr($path, 'write', isset($stat['write']) ? !!$stat['write'] : null));
if ($root) {
$stat['locked'] = 1;
} elseif ($this->attr($path, 'locked', !empty($stat['locked']))) {
$stat['locked'] = 1;
} else {
unset($stat['locked']);
}
if ($root) {
unset($stat['hidden']);
} elseif ($this->attr($path, 'hidden', !empty($stat['hidden'])) || !$this->mimeAccepted($stat['mime'])) {
$stat['hidden'] = $root ? 0 : 1;
} else {
unset($stat['hidden']);
}
if ($stat['read'] && empty($stat['hidden'])) {
if ($stat['mime'] == 'directory') {
// for dir - check for subdirs
if ($this->options['checkSubfolders']) {
if (isset($stat['dirs'])) {
if ($stat['dirs']) {
$stat['dirs'] = 1;
} else {
unset($stat['dirs']);
}
} elseif (!empty($stat['alias']) && !empty($stat['target'])) {
$stat['dirs'] = isset($this->cache[$stat['target']]) ? intval(isset($this->cache[$stat['target']]['dirs'])) : $this->_subdirs($stat['target']);
} elseif ($this->_subdirs($path)) {
$stat['dirs'] = 1;
}
} else {
$stat['dirs'] = 1;
}
} else {
// for files - check for thumbnails
$p = isset($stat['target']) ? $stat['target'] : $path;
if ($this->tmbURL && !isset($stat['tmb']) && $this->canCreateTmb($p, $stat)) {
$tmb = $this->gettmb($p, $stat);
$stat['tmb'] = $tmb ? $tmb : 1;
}
}
}
if (!empty($stat['alias']) && !empty($stat['target'])) {
$stat['thash'] = $this->encode($stat['target']);
unset($stat['target']);
}
return $this->cache[$path] = $stat;
}