elFinderVolumeFTP::parseRaw PHP Method

parseRaw() protected method

Parse line from ftp_rawlist() output and return file stat (array)
Author: Dmitry Levashov
protected parseRaw ( string $raw, $base, boolean $nameOnly = false ) : array
$raw string line from ftp_rawlist() output
$base
$nameOnly boolean
return array
    protected function parseRaw($raw, $base, $nameOnly = false)
    {
        static $now;
        static $lastyear;
        if (!$now) {
            $now = time();
            $lastyear = date('Y') - 1;
        }
        $info = preg_split("/\\s+/", $raw, 9);
        $stat = array();
        if (!isset($this->ftpOsUnix)) {
            $this->ftpOsUnix = !preg_match('/\\d/', substr($info[0], 0, 1));
        }
        if (!$this->ftpOsUnix) {
            $info = $this->normalizeRawWindows($raw);
        }
        if (count($info) < 9 || $info[8] == '.' || $info[8] == '..') {
            return false;
        }
        $name = $info[8];
        if (preg_match('|(.+)\\-\\>(.+)|', $name, $m)) {
            $name = trim($m[1]);
            // check recursive processing
            if ($this->cacheDirTarget && $this->_joinPath($base, $name) !== $this->cacheDirTarget) {
                return array();
            }
            if (!$nameOnly) {
                $target = trim($m[2]);
                if (substr($target, 0, 1) !== $this->separator) {
                    $target = $this->getFullPath($target, $base);
                }
                $target = $this->_normpath($target);
                $stat['name'] = $name;
                $stat['target'] = $target;
                return $stat;
            }
        }
        if ($nameOnly) {
            return array('name' => $name);
        }
        if (is_numeric($info[5]) && !$info[6] && !$info[7]) {
            // by normalizeRawWindows()
            $stat['ts'] = $info[5];
        } else {
            $stat['ts'] = strtotime($info[5] . ' ' . $info[6] . ' ' . $info[7]);
            if ($stat['ts'] && $stat['ts'] > $now && strpos($info[7], ':') !== false) {
                $stat['ts'] = strtotime($info[5] . ' ' . $info[6] . ' ' . $lastyear . ' ' . $info[7]);
            }
            if (empty($stat['ts'])) {
                $stat['ts'] = strtotime($info[6] . ' ' . $info[5] . ' ' . $info[7]);
                if ($stat['ts'] && $stat['ts'] > $now && strpos($info[7], ':') !== false) {
                    $stat['ts'] = strtotime($info[6] . ' ' . $info[5] . ' ' . $lastyear . ' ' . $info[7]);
                }
            }
        }
        if ($this->options['statOwner']) {
            $stat['owner'] = $info[2];
            $stat['group'] = $info[3];
            $stat['perm'] = substr($info[0], 1);
            $stat['isowner'] = $stat['owner'] ? $stat['owner'] == $this->options['user'] : $this->options['owner'];
        }
        $owner = isset($stat['owner']) ? $stat['owner'] : '';
        $perm = $this->parsePermissions($info[0], $owner);
        $stat['name'] = $name;
        $stat['mime'] = substr(strtolower($info[0]), 0, 1) == 'd' ? 'directory' : $this->mimetype($stat['name']);
        $stat['size'] = $stat['mime'] == 'directory' ? 0 : $info[4];
        $stat['read'] = $perm['read'];
        $stat['write'] = $perm['write'];
        return $stat;
    }