Overview

Packages

  • Vfs

Classes

  • Horde_Vfs
  • Horde_Vfs_Base
  • Horde_Vfs_Browser
  • Horde_Vfs_Exception
  • Horde_Vfs_File
  • Horde_Vfs_Ftp
  • Horde_Vfs_Gc
  • Horde_Vfs_Horde
  • Horde_Vfs_Kolab
  • Horde_Vfs_ListItem
  • Horde_Vfs_Musql
  • Horde_Vfs_Object
  • Horde_Vfs_Smb
  • Horde_Vfs_Sql
  • Horde_Vfs_SqlFile
  • Horde_Vfs_Ssh2
  • Horde_Vfs_Translation
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * VFS implementation for the Horde Application Framework.
  4:  *
  5:  * Required parameters:<pre>
  6:  *   'horde_base'  Filesystem location of a local Horde installation.</pre>
  7:  *
  8:  * Optional parameters:<pre>
  9:  *   'user'      A valid Horde user name.
 10:  *   'password'  The user's password.</pre>
 11:  *
 12:  * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
 13:  *
 14:  * See the enclosed file COPYING for license information (LGPL). If you
 15:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 16:  *
 17:  * @author  Jan Schneider <jan@horde.org>
 18:  * @package Vfs
 19:  */
 20: class Horde_Vfs_Horde extends Horde_Vfs_Base
 21: {
 22:     /**
 23:      * Reference to a Horde Registry instance.
 24:      *
 25:      * @var Horde_Registry
 26:      */
 27:     protected $_registry;
 28: 
 29:     /**
 30:      * Constructor.
 31:      *
 32:      * @param array $params  A hash containing connection parameters.
 33:      * @throws Horde_Vfs_Exception
 34:      */
 35:     public function __construct($params = array())
 36:     {
 37:         parent::__construct($params);
 38: 
 39:         if (!isset($this->_params['horde_base'])) {
 40:             throw new Horde_Vfs_Exception('Required "horde_base" not specified in VFS configuration.');
 41:         }
 42: 
 43:         require_once $this->_params['horde_base'] . '/lib/Application.php';
 44:         Horde_Registry::appInit('horde');
 45: 
 46:         // Create the Registry object.
 47:         $this->_registry = $GLOBALS['registry'];
 48:     }
 49: 
 50:     /**
 51:      */
 52:     protected function _connect()
 53:     {
 54:         if (!empty($this->_params['user']) &&
 55:             !empty($this->_params['password'])) {
 56:             $GLOBALS['registry']->setAuth($this->_params['user'], array('password' => $this->_params['password']));
 57:         }
 58:     }
 59: 
 60:     /**
 61:      * Retrieves a file from the VFS.
 62:      *
 63:      * @param string $path  The pathname to the file.
 64:      * @param string $name  The filename to retrieve.
 65:      *
 66:      * @return string  The file data.
 67:      */
 68:     public function read($path, $name)
 69:     {
 70:         if (substr($path, 0, 1) == '/') {
 71:             $path = substr($path, 1);
 72:         }
 73:         $pieces = explode('/', $path);
 74: 
 75:         try {
 76:             $data = $this->_registry->callByPackage($pieces[0], 'browse', array('path' => $path . '/' . $name));
 77:         } catch (Horde_Exception $e) {
 78:             return '';
 79:         }
 80: 
 81:         return is_object($data) ? $data : $data['data'];
 82:     }
 83: 
 84:     /**
 85:      * Returns an an unsorted file list of the specified directory.
 86:      *
 87:      * @param string $path       The path of the directory.
 88:      * @param mixed $filter      String/hash to filter file/dirname on.
 89:      * @param boolean $dotfiles  Show dotfiles?
 90:      * @param boolean $dironly   Show only directories?
 91:      *
 92:      * @return array  File list.
 93:      * @throws Horde_Vfs_Exception
 94:      */
 95:     protected function _listFolder($path, $filter = null, $dotfiles = true,
 96:                                    $dironly = false)
 97:     {
 98:         $list = array();
 99:         if ($path == '/') {
100:             try {
101:                 $apps = $this->_registry->listApps(null, false, Horde_Perms::READ);
102:             } catch (Horde_Exception $e) {
103:                 throw new Horde_Vfs_Exception($e->getMessage());
104:             }
105: 
106:             foreach ($apps as $app) {
107:                 if ($this->_registry->hasMethod('browse', $app)) {
108:                     $file = array(
109:                         //'name' => $this->_registry->get('name', $app),
110:                         'name' => $app,
111:                         'date' => time(),
112:                         'type' => '**dir',
113:                         'size' => -1
114:                     );
115:                     $list[] = $file;
116:                 }
117:             }
118:             return $list;
119:         }
120: 
121:         if (substr($path, 0, 1) == '/') {
122:             $path = substr($path, 1);
123:         }
124:         $pieces = explode('/', $path);
125: 
126:         try {
127:             $items = $this->_registry->callByPackage($pieces[0], 'browse', array('path' => $path, 'properties' => array('name', 'browseable', 'contenttype', 'contentlength', 'modified')));
128:         } catch (Horde_Exception $e) {
129:             throw new Horde_Vfs_Exception($e->getMessage());
130:         }
131: 
132:         if (!is_array(reset($items))) {
133:             /* We return an object's content. */
134:             throw new Horde_Vfs_Exception('Unknown error');
135:         }
136: 
137:         foreach ($items as $sub_path => $i) {
138:             if ($dironly && !$i['browseable']) {
139:                 continue;
140:             }
141: 
142:             $name = basename($sub_path);
143:             if ($this->_filterMatch($filter, $name)) {
144:                 continue;
145:             }
146: 
147:             $type = class_exists('Horde_Mime_Magic')
148:                 ? Horde_Mime_Magic::mimeToExt(empty($i['contenttype']) ? 'application/octet-stream' : $i['contenttype'])
149:                 : '**none';
150: 
151:             $file = array(
152:                 //'name' => $i['name'],
153:                 'name' => $name,
154:                 'date' => empty($i['modified']) ? 0 : $i['modified'],
155:                 'type' => $i['browseable'] ? '**dir' : $type,
156:                 'size' => empty($i['contentlength']) ? 0 : $i['contentlength']
157:             );
158:             $list[] = $file;
159:         }
160: 
161:         return $list;
162:     }
163: 
164: }
165: 
API documentation generated by ApiGen