1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Ingo_Transport_Vfs extends Ingo_Transport
15: {
16: 17: 18: 19: 20:
21: public function __construct($params = array())
22: {
23: $this->_support_shares = true;
24:
25: $default_params = array(
26: 'hostspec' => 'localhost',
27: 'port' => 21,
28: 'filename' => '.ingo_filter',
29: 'vfstype' => 'ftp',
30: 'vfs_path' => '',
31: 'vfs_forward_path' => '',
32: );
33:
34: parent::__construct(array_merge($default_params, $params));
35: }
36:
37: 38: 39: 40: 41: 42: 43: 44:
45: public function setScriptActive($script, $additional = array())
46: {
47: $this->_connect();
48:
49: try {
50: if (!empty($script)) {
51: $this->_vfs->writeData($this->_params['vfs_path'], $this->_params['filename'], $script, true);
52: } elseif ($this->_vfs->exists($this->_params['vfs_path'], $this->_params['filename'])) {
53: $this->_vfs->deleteFile($this->_params['vfs_path'], $this->_params['filename']);
54: }
55: foreach ($additional as $filename => $content) {
56: if (strlen($content)) {
57: $this->_vfs->writeData($this->_params['vfs_path'], $filename, $content, true);
58: } elseif ($this->_vfs->exists($this->_params['vfs_path'], $filename)) {
59: $this->_vfs->deleteFile($this->_params['vfs_path'], $filename);
60: }
61: }
62: } catch (Horde_Vfs_Exception $e) {
63: throw new Ingo_Exception($e);
64: }
65:
66: if (isset($this->_params['file_perms'])) {
67: try {
68: if (!empty($script)) {
69: $this->_vfs->changePermissions($this->_params['vfs_path'], $this->_params['filename'], $this->_params['file_perms']);
70: }
71: foreach ($additional as $filename => $content) {
72: if (strlen($content)) {
73: $this->_vfs->changePermissions($this->_params['vfs_path'], $filename, $this->_params['file_perms']);
74: }
75: }
76: } catch (Horde_Vfs_Exception $e) {
77: throw new Ingo_Exception($e);
78: }
79: }
80: }
81:
82: 83: 84: 85: 86: 87:
88: public function getScript()
89: {
90: $this->_connect();
91: try {
92: return $this->_vfs->read($this->_params['vfs_path'], $this->_params['filename']);
93: } catch (Horde_Vfs_Exception $e) {
94: throw new Ingo_Exception($e);
95: }
96: }
97:
98: 99: 100: 101: 102:
103: protected function _connect()
104: {
105:
106: if (!empty($this->_params['vfs_path'])) {
107: $user = Ingo::getUser();
108: $domain = Ingo::getDomain();
109: if ($GLOBALS['session']->get('ingo', 'backend/hordeauth') !== 'full') {
110: $pos = strpos($user, '@');
111: if ($pos !== false) {
112: $domain = substr($user, $pos + 1);
113: $user = substr($user, 0, $pos);
114: }
115: }
116: $this->_params['vfs_path'] = str_replace(
117: array('%u', '%d', '%U'),
118: array($user, $domain, $this->_params['username']),
119: $this->_params['vfs_path']);
120: }
121:
122: if (!empty($this->_vfs)) {
123: return true;
124: }
125:
126: try {
127: $this->_vfs = $GLOBALS['injector']
128: ->getInstance('Horde_Core_Factory_Vfs')
129: ->create('ingo', array('type' => $this->_params['vfstype'],
130: 'params' => $this->_params));
131: } catch (Horde_Exception $e) {
132: throw new Ingo_Exception($e);
133: }
134: }
135: }
136: