1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: if (!defined('CHORA_BASE')) {
17: define('CHORA_BASE', dirname(__FILE__) . '/..');
18: }
19:
20: if (!defined('HORDE_BASE')) {
21: 22:
23: if (file_exists(CHORA_BASE . '/config/horde.local.php')) {
24: include CHORA_BASE . '/config/horde.local.php';
25: } else {
26: define('HORDE_BASE', CHORA_BASE . '/..');
27: }
28: }
29:
30: 31:
32: require_once HORDE_BASE . '/lib/core.php';
33:
34: class Chora_Application extends Horde_Registry_Application
35: {
36: 37:
38: public $version = 'H4 (3.0-git)';
39:
40: 41: 42: 43: 44:
45: protected function _init()
46: {
47: global $acts, $conf, $defaultActs, $where, $atdir, $fullname, $sourceroot;
48:
49: try {
50: $GLOBALS['sourceroots'] = Horde::loadConfiguration('backends.php', 'sourceroots');
51: } catch (Horde_Exception $e) {
52: $GLOBALS['sourceroots'] = array();
53:
54:
55:
56: if ($GLOBALS['registry']->initialApp != 'chora') {
57: return;
58: }
59: $GLOBALS['notification']->push($e);
60: }
61:
62: $sourceroots = Chora::sourceroots();
63:
64: 65: 66: 67: 68: 69: 70: 71: 72: 73:
74: $defaultActs = $acts = array(
75: 'onb' => 0,
76: 'ord' => Horde_Vcs::SORT_ASCENDING,
77: 'rev' => 0,
78: 'rt' => null,
79: 'sa' => 0,
80: 'sbt' => constant($conf['options']['defaultsort']),
81: 'ws' => 1,
82: );
83:
84: 85:
86: $vars = Horde_Variables::getDefaultVariables();
87: foreach (array_keys($acts) as $key) {
88: if (isset($vars->$key)) {
89: $acts[$key] = $vars->$key;
90: }
91: }
92:
93: 94: 95:
96: if (is_null($acts['rt'])) {
97: $last_sourceroot = $GLOBALS['prefs']->getValue('last_sourceroot');
98:
99: if (!empty($last_sourceroot) &&
100: !empty($sourceroots[$last_sourceroot]) &&
101: is_array($sourceroots[$last_sourceroot])) {
102: $acts['rt'] = $last_sourceroot;
103: } else {
104: foreach ($sourceroots as $key => $val) {
105: if (!isset($acts['rt']) || isset($val['default'])) {
106: $acts['rt'] = $key;
107: break;
108: }
109: }
110:
111: if (is_null($acts['rt'])) {
112: Chora::fatal(new Chora_Exception(_("No repositories found.")));
113: }
114: }
115: }
116:
117: if (!isset($sourceroots[$acts['rt']])) {
118: Chora::fatal(new Chora_Exception(sprintf(_("The repository with the slug '%s' was not found"), $acts['rt'])));
119: }
120:
121: $sourcerootopts = $sourceroots[$acts['rt']];
122: $sourceroot = $acts['rt'];
123:
124:
125: $cache = empty($conf['caching'])
126: ? null
127: : $GLOBALS['injector']->getInstance('Horde_Cache');
128:
129: $GLOBALS['chora_conf'] = array(
130: 'cvsusers' => $sourcerootopts['location'] . '/' . (isset($sourcerootopts['cvsusers']) ? $sourcerootopts['cvsusers'] : ''),
131: 'introText' => CHORA_BASE . '/config/' . (isset($sourcerootopts['intro']) ? $sourcerootopts['intro'] : ''),
132: 'introTitle' => (isset($sourcerootopts['title']) ? $sourcerootopts['title'] : ''),
133: 'sourceRootName' => $sourcerootopts['name']
134: );
135: $chora_conf = &$GLOBALS['chora_conf'];
136:
137: $GLOBALS['VC'] = Horde_Vcs::factory(Horde_String::ucfirst($sourcerootopts['type']), array(
138: 'cache' => $cache,
139: 'sourceroot' => $sourcerootopts['location'],
140: 'paths' => array_merge($conf['paths'], array('temp' => Horde::getTempDir())),
141: 'username' => isset($sourcerootopts['username']) ? $sourcerootopts['username'] : '',
142: 'password' => isset($sourcerootopts['password']) ? $sourcerootopts['password'] : ''
143: ));
144:
145: $where = Horde_Util::getFormData('f', '/');
146:
147:
148: $where = preg_replace(array('|^/|', '|\.\.|'), '', $where);
149:
150:
151: $GLOBALS['prefs']->setValue('last_sourceroot', $acts['rt']);
152:
153: $fullname = $sourcerootopts['location'] . (substr($sourcerootopts['location'], -1) == '/' ? '' : '/') . $where;
154:
155: if ($sourcerootopts['type'] == 'cvs') {
156: $fullname = preg_replace('|/$|', '', $fullname);
157: $atdir = @is_dir($fullname);
158: } else {
159: $atdir = !$where || (substr($where, -1) == '/');
160: }
161: $where = preg_replace('|/$|', '', $where);
162:
163: if (($sourcerootopts['type'] == 'cvs') &&
164: !@is_dir($sourcerootopts['location'])) {
165: Chora::fatal(new Chora_Exception(_("Sourceroot not found. This could be a misconfiguration by the server administrator, or the server could be having temporary problems. Please try again later.")));
166: }
167:
168: if (Chora::isRestricted($where)) {
169: Chora::fatal(new Chora_Exception(sprintf(_("%s: Forbidden by server configuration"), $where)));
170: }
171: }
172:
173: 174:
175: public function perms()
176: {
177: $perms = array(
178: 'sourceroots' => array(
179: 'title' => _("Repositories")
180: )
181: );
182:
183:
184: require dirname(__FILE__) . '/../config/backends.php';
185: foreach ($sourceroots as $sourceroot => $srconfig) {
186: $perms['sourceroots:' . $sourceroot] = array(
187: 'title' => $srconfig['name']
188: );
189: }
190:
191: return $perms;
192: }
193:
194: 195:
196: public function ($menu)
197: {
198: $menu->add(Chora::url('browsedir'), _("_Browse"), 'chora.png');
199: }
200:
201:
202:
203: 204:
205: public function (Horde_Tree_Base $tree, $parent = null,
206: array $params = array())
207: {
208: asort($GLOBALS['sourceroots']);
209:
210: foreach ($GLOBALS['sourceroots'] as $key => $val) {
211: if (Chora::checkPerms($key)) {
212: $tree->addNode($parent . $key,
213: $parent,
214: $val['name'],
215: 1,
216: false,
217: array(
218: 'icon' => Horde_Themes::img('tree/folder.png'),
219: 'url' => Chora::url('browsedir', '', array('rt' => $key))->setRaw(true)
220: )
221: );
222: }
223: }
224: }
225:
226: }
227: