1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class Horde_Vfs_Horde extends Horde_Vfs_Base
21: {
22: 23: 24: 25: 26:
27: protected $_registry;
28:
29: 30: 31: 32: 33: 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:
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: 62: 63: 64: 65: 66: 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: 86: 87: 88: 89: 90: 91: 92: 93: 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:
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:
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:
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: