/**
  * 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
  **/
 protected function _stat($path)
 {
     $stat = array('mime' => 'directory', 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'size' => 0);
     // If root, just return from above
     if ($this->root == $path) {
         $stat['name'] = $this->root;
         return $stat;
     }
     // If not exists, return empty
     if (!$this->fs->has($path)) {
         return array();
     }
     $meta = $this->fs->getMetadata($path);
     // Get timestamp/size
     $stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
     $stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
     // Check if file, if so, check mimetype
     if ($meta['type'] == 'file') {
         $stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
         $imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
         if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
             $stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
             $stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
         }
     }
     if (!isset($stat['url']) && $this->fs->getUrl()) {
         $stat['url'] = 1;
     }
     return $stat;
 }
Пример #2
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
  **/
 protected function _stat($path)
 {
     $stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory');
     // If root, just return from above
     if ($this->root == $path) {
         $stat['name'] = $this->root;
         return $stat;
     }
     // If not exists, return empty
     if (!$this->fs->has($path)) {
         // Check if the parent doesn't have this path
         if ($this->_dirExists($path)) {
             return $stat;
         }
         // Neither a file or directory exist, return empty
         return array();
     }
     $meta = $this->fs->getMetadata($path);
     // return empty on failure
     if (!$meta) {
         return array();
     }
     // Set item filename.extension to `name` if exists
     if (isset($meta['filename']) && isset($meta['extension'])) {
         $stat['name'] = $meta['filename'];
         if ($meta['extension'] !== '') {
             $stat['name'] .= '.' . $meta['extension'];
         }
     }
     // Get timestamp/size if available
     if (isset($meta['timestamp'])) {
         $stat['ts'] = $meta['timestamp'];
     }
     if (isset($meta['size'])) {
         $stat['size'] = $meta['size'];
     }
     // Check if file, if so, check mimetype when available
     if ($meta['type'] == 'file') {
         $stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : null;
         $imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
         if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
             $stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
             $stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
         }
     }
     if (!isset($stat['url']) && $this->fs->getUrl()) {
         $stat['url'] = 1;
     }
     return $stat;
 }
Пример #3
0
 /**
  * Generate a photo URL
  *
  * @param string $photo
  * @param array $options
  * @return string
  */
 public function generate($photo, $options = [])
 {
     return $this->webPath . '/argentique/p.php' . $this->builder->getUrl($photo, $options);
 }