コード例 #1
0
ファイル: Sql.php プロジェクト: raz0rsdge/horde
 /**
  * Returns an an unsorted file list of the specified directory.
  *
  * @param string $path          The path of the directory.
  * @param string|array $filter  Regular expression(s) to filter
  *                              file/directory name on.
  * @param boolean $dotfiles     Show dotfiles?
  * @param boolean $dironly      Show only directories?
  *
  * @return array  File list.
  * @throws Horde_Vfs_Exception
  */
 protected function _listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
 {
     if (!$this->isFolder(dirname($path), basename($path))) {
         throw new Horde_Vfs_Exception(sprintf('"%s" is not a folder.', $path));
     }
     $path = $this->_convertPath($path);
     list($op, $values) = $this->_nullString($path);
     try {
         $length_op = $this->_getFileSizeOp();
         $sql = sprintf('SELECT vfs_name, vfs_type, %s(vfs_data) length, vfs_modified, vfs_owner FROM %s WHERE vfs_path %s', $length_op, $this->_params['table'], $op);
         $fileList = $this->_db->select($sql, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Vfs_Exception($e);
     }
     $files = array();
     foreach ($fileList as $line) {
         // Filter out dotfiles if they aren't wanted.
         if (!$dotfiles && substr($line['vfs_name'], 0, 1) == '.') {
             continue;
         }
         $file['name'] = $line['vfs_name'];
         if ($line['vfs_type'] == self::FILE) {
             $name = explode('.', $line['vfs_name']);
             if (count($name) == 1) {
                 $file['type'] = '**none';
             } else {
                 $file['type'] = Horde_String::lower($name[count($name) - 1]);
             }
             $file['size'] = $line['length'];
         } elseif ($line['vfs_type'] == self::FOLDER) {
             $file['type'] = '**dir';
             $file['size'] = -1;
         }
         $file['date'] = $line['vfs_modified'];
         $file['owner'] = isset($line['vfs_owner']) ? $line['vfs_owner'] : '';
         $file['perms'] = '';
         $file['group'] = '';
         // filtering
         if ($this->_filterMatch($filter, $file['name'])) {
             unset($file);
             continue;
         }
         if ($dironly && $file['type'] !== '**dir') {
             unset($file);
             continue;
         }
         $files[$file['name']] = $file;
         unset($file);
     }
     return $files;
 }