1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Trean
16: {
17: public static function initialize()
18: {
19:
20: if ($GLOBALS['registry']->getAuth() && !$GLOBALS['trean_shares']->exists($GLOBALS['registry']->getAuth())) {
21: $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
22: $name = $identity->getValue('fullname');
23: if (trim($name) == '') {
24: $name = $GLOBALS['registry']->getAuth();
25: }
26: $folder = $GLOBALS['trean_shares']->newFolder($GLOBALS['registry']->getAuth(), array('name' => sprintf(_("%s's Bookmarks"), $name)));
27: $result = $GLOBALS['trean_shares']->addFolder($folder);
28: if ($result instanceof PEAR_Error) {
29: throw new Horde_Exception($result);
30: }
31: }
32: }
33:
34: 35:
36: function getDb()
37: {
38: $config = $GLOBALS['conf']['sql'];
39: unset($config['charset']);
40: return MDB2::factory($config);
41: }
42:
43: 44: 45: 46: 47:
48: function listFolders($perm = Horde_Perms::SHOW, $parent = null, $allLevels = true)
49: {
50: return $GLOBALS['trean_shares']->getFolders($GLOBALS['registry']->getAuth(), $perm, $parent, $allLevels);
51: }
52:
53: 54: 55: 56: 57: 58: 59: 60:
61: function countFolders($perm = Horde_Perms::SHOW)
62: {
63: $folders = $GLOBALS['trean_shares']->listFolders($GLOBALS['registry']->getAuth(), $perm);
64: if (is_a($folders, 'PEAR_Error')) {
65: $GLOBALS['notification']->push(sprintf(_("An error occurred counting folders: %s"), $folders->getMessage()), 'horde.error');
66: return 0;
67: }
68: return count($folders);
69: }
70:
71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81:
82: function folderSelect($selected = null, $perm = Horde_Perms::SHOW, $new = false)
83: {
84:
85: if (is_null($selected)) {
86: $selected = $GLOBALS['registry']->getAuth();
87: }
88:
89: $folders = Trean::listFolders($perm);
90: if (is_a($folders, 'PEAR_Error')) {
91: $folders = array();
92: }
93:
94: $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('folder_select', 'Select');
95:
96: foreach ($folders as $folder_name => $folder) {
97:
98: $params['selected'] = ($folder->getId() == $selected || $folder_name == $selected);
99:
100:
101: $tree->addNode($folder->getId(), $folder->getParent(), $folder->get('name'), substr_count($folder_name, ':'), true, $params);
102: }
103:
104: $select = $new
105: ? '<option value="">----</option><option value="*new*">' . _("New Folder") . '</option>'
106: : '';
107:
108: return $select . $tree->renderTree();
109: }
110:
111: 112:
113: function sortOrder($sortby)
114: {
115: switch ($sortby) {
116: case 'title':
117: return 0;
118:
119: case 'rating':
120: case 'clicks':
121: return 1;
122: }
123: }
124:
125: 126: 127: 128: 129: 130: 131: 132:
133: function hasPermission($permission)
134: {
135: $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
136: if (!$perms->exists('trean:' . $permission)) {
137: return true;
138: }
139:
140: $allowed = $perms->getPermissions('trean:' . $permission, $GLOBALS['registry']->getAuth());
141: if (is_array($allowed)) {
142: switch ($permission) {
143: case 'max_folders':
144: case 'max_bookmarks':
145: $allowed = max($allowed);
146: break;
147: }
148: }
149:
150: return $allowed;
151: }
152:
153: 154: 155: 156:
157: function HTTPStatus($status_code)
158: {
159: switch ($status_code) {
160: case '100': return _("Continue");
161: case '101': return _("Switching Protocols");
162: case '200': return _("OK");
163: case '201': return _("Created");
164: case '202': return _("Accepted");
165: case '203': return _("Non-Authoritative Information");
166: case '204': return _("No Content");
167: case '205': return _("Reset Content");
168: case '206': return _("Partial Content");
169: case '300': return _("Multiple Choices");
170: case '301': return _("Moved Permanently");
171: case '302': return _("Found");
172: case '303': return _("See Other");
173: case '304': return _("Not Modified");
174: case '305': return _("Use Proxy");
175: case '307': return _("Temporary Redirect");
176: case '400': return _("Bad Request");
177: case '401': return _("Unauthorized");
178: case '402': return _("Payment Required");
179: case '403': return _("Forbidden");
180: case '404': return _("Not Found");
181: case '405': return _("Method Not Allowed");
182: case '406': return _("Not Acceptable");
183: case '407': return _("Proxy Authentication Required");
184: case '408': return _("Request Time-out");
185: case '409': return _("Conflict");
186: case '410': return _("Gone");
187: case '411': return _("Length Required");
188: case '412': return _("Precondition Failed");
189: case '413': return _("Request Entity Too Large");
190: case '414': return _("Request-URI Too Large");
191: case '415': return _("Unsupported Media Type");
192: case '416': return _("Requested range not satisfiable");
193: case '417': return _("Expectation Failed");
194: case '500': return _("Internal Server Error");
195: case '501': return _("Not Implemented");
196: case '502': return _("Bad Gateway");
197: case '503': return _("Service Unavailable");
198: case '504': return _("Gateway Time-out");
199: case '505': return _("HTTP Version not supported");
200: default: return '';
201: }
202: }
203:
204: 205: 206:
207: function getFavicon($bookmark)
208: {
209: global $registry;
210:
211:
212: try {
213: $vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create();
214: if ($bookmark->favicon
215: && $vfs->exists('.horde/trean/favicons/', $bookmark->favicon)) {
216: return Horde_Util::addParameter(Horde::url('favicon.php'),
217: 'bookmark_id', $bookmark->id);
218: }
219: } catch (Exception $e) {
220: }
221:
222:
223: $protocol = substr($bookmark->url, 0, strpos($bookmark->url, '://'));
224: return Horde_Themes::img('/protocol/' . (empty($protocol) ? 'http' : $protocol) . '.png');
225: }
226: }
227: