Exemple #1
0
	/**
	 * Return stat for given path.
	 * Stat contains following fields:
	 * - (int)    size    file size in b. required
	 * - (int)    ts      file modification time in unix time. required
	 * - (string) mime    mimetype. required for folders, others - optionally
	 * - (bool)   read    read permissions. required
	 * - (bool)   write   write permissions. required
	 * - (bool)   locked  is object locked. optionally
	 * - (bool)   hidden  is object hidden. optionally
	 * - (string) alias   for symlinks - link target path relative to root path. optionally
	 * - (string) target  for symlinks - link target path. optionally
	 *
	 * If file does not exists - returns empty array or false.
	 *
	 * @param  string  $path    file path
	 * @return array|false
	 * @author Dmitry (dio) Levashov
	 * @author Naoki Sawada
	 **/
	protected function _stat($path) {
		if ($path === '_') {
			$cid = $lid = 0;
		} else {
			list($cid, $lid) = explode('_', substr($path, 1), 2);
			list($lid) = explode('.', $lid);
			list($lid, $cnt) = array_pad(explode('_', $lid), 2, '');
			if ($cnt) {
				$cnt = (int)$cnt;
			}
		}
		$stat_def = array(
			'size' => 0,
			'ts' => 0,
			'mime' => '',
			'dirs' => 0,
			'read' => true,
			'write' => false,
			'locked' => true,
			'hidden' => false
		);

		if (! $cid) {
			$stat['name'] = (! empty($this->options['alias'])? $this->options['alias'] : 'untitle');
			$stat['mime'] = 'directory';
			$stat['dirs'] = true;
			$stat = array_merge($stat_def, $stat);
			return $stat;
		} elseif (! $lid) {
			// cat (dirctory)
			$sql = 'SELECT c.pid, c.cid, c.title as name , s.pid as dirs ' .
					'FROM '.$this->tbc.' AS c ' .
					'LEFT JOIN '.$this->tbc.' AS s ON c.cid=s.pid ' .
					'WHERE c.cid="'.$cid.'" LIMIT 1';
			$res = $this->query($sql);
			if ($res) {
				$stat = $this->db->fetchArray($res);
				$stat = array_merge($stat_def, $stat);
				$stat['mime'] = 'directory';
				$stat['dirs'] = $stat['dirs']? 1 : 0;
				if (! $stat['pid']) {
					$stat['phash'] = $this->encode('_');
				} else {
					$stat['phash'] = $this->encode('_'.$stat['pid'].'_');
				}
				unset($stat['cid'], $stat['pid']);
				return $stat;
			}
		} elseif ($cid) {
			// photos
			$sql = 'SELECT submitter as uid, lid, concat( lid, "'.($cnt? ('_' . $cnt) : '').'.", ext'.$cnt.' ) AS id, res_x'.$cnt.' AS width, res_y'.$cnt.' AS height, `date` AS ts, concat( title, "'.($cnt? ('_' . $cnt) : '').'.", ext'.$cnt.' ) AS name
					FROM '.$this->tbf.'
					WHERE lid="'.$lid.'" AND status>0 LIMIT 1';
			$res = $this->query($sql);
			if ($res) {
				$stat = $this->db->fetchArray($res);
				$stat = array_merge($stat_def, $stat);
				$stat['phash'] = $this->encode('_'.$cid.'_');
				$stat['url'] = $this->options['URL'].$stat['id'];
				$realpath = realpath($this->options['filePath'].$stat['id']);
				$stat['size'] = filesize($realpath);
				$stat['mime'] = $this->mimetypeInternalDetect($stat['id']);
				$stat['simg'] = trim($this->options['smallImg'], '/');
				$stat['tooltip'] = 'Owner: ' . xoops_elFinder::getUnameByUid($stat['uid']);
				unset($stat['lid'], $stat['id']);
				return $stat;
			}
		}

		return array();
	}
Exemple #2
0
 protected function makeStat($stat)
 {
     if ($stat['parent_id']) {
         $stat['phash'] = $this->encode($stat['parent_id']);
     } else {
         $stat['phash'] = null;
     }
     if ($stat['mime'] == 'directory') {
         unset($stat['width']);
         unset($stat['height']);
     } else {
         unset($stat['dirs']);
     }
     $this->setAuthByPerm($stat);
     $name = $stat['name'];
     if ($stat['mime'] !== 'directory') {
         if (strpos($this->options['URL'], '?') === false) {
             $stat['url'] = $this->options['URL'] . $stat['file_id'] . '/' . rawurlencode($name);
             // Use pathinfo "index.php/[id]/[name]
         } else {
             $stat['url'] = $this->options['URL'] . $stat['file_id'] . '&' . rawurlencode($name);
         }
     } else {
         $stat['url'] = null;
     }
     if (!empty($stat['local_path'])) {
         $stat['_localalias'] = 1;
         $stat['alias'] = $stat['local_path'];
         $stat['write'] = 0;
     }
     if (isset($stat['uid'])) {
         $stat['owner'] = xoops_elFinder::getUnameByUid($stat['uid']);
         $stat['tooltip'] = 'Owner: ' . $stat['owner'];
     }
     unset($stat['file_id'], $stat['parent_id'], $stat['gid'], $stat['home_of'], $stat['local_path']);
     if (empty($stat['isowner'])) {
         unset($stat['perm'], $stat['uid'], $stat['gids']);
     }
     if (empty($stat['isowner']) || $stat['mime'] !== 'directory') {
         unset($stat['umask']);
     }
     if ($stat['mime'] !== 'directory') {
         unset($stat['filter']);
     }
     return $stat;
 }