1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Jonah
16: {
17: 18: 19:
20: const INTERNAL_CHANNEL = 0;
21:
22: 23: 24:
25: const COMPOSITE_CHANNEL = 3;
26:
27: 28:
29: const ORDER_PUBLISHED = 0;
30: const ORDER_READ = 1;
31: const = 2;
32:
33: 34: 35: 36: 37: 38: 39:
40: static public function readURL($url)
41: {
42: global $conf;
43:
44: $http = $GLOBALS['injector']
45: ->getInstance('Horde_Core_Factory_HttpClient')
46: ->create();
47:
48: try {
49: $response = $http->get($url);
50: } catch (Horde_Http_Exception $e) {
51: throw new Jonah_Exception(sprintf(_("Could not open %s: %s"), $url, $e->getMessage()));
52: }
53: if ($response->code <> '200') {
54: throw new Jonah_Exception(sprintf(_("Could not open %s: %s"), $url, $response->code));
55: }
56: $result = array('body' => $response->getBody());
57: $content_type = $response->getHeader('Content-Type');
58: if (preg_match('/.*;\s?charset="?([^"]*)/', $content_type, $match)) {
59: $result['charset'] = $match[1];
60: } elseif (preg_match('/<\?xml[^>]+encoding=["\']?([^"\'\s?]+)[^?].*?>/i', $result['body'], $match)) {
61: $result['charset'] = $match[1];
62: }
63:
64: return $result;
65: }
66:
67: 68: 69:
70: static public function getChannelTypeLabel($type)
71: {
72: switch ($type) {
73: case Jonah::INTERNAL_CHANNEL:
74: return _("Local Feed");
75: }
76: }
77:
78: 79: 80: 81: 82: 83: 84: 85: 86:
87: static public function checkPermissions($filter, $permission = Horde_Perms::READ, $in = null)
88: {
89: if ($GLOBALS['registry']->isAdmin(array('permission' => 'jonah:admin', 'permlevel' => $permission))) {
90: if (empty($in)) {
91:
92:
93:
94:
95: return is_array($in) ? array() : true;
96: } else {
97: return $in;
98: }
99: }
100:
101: $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
102:
103: $out = array();
104:
105: switch ($filter) {
106: case 'internal_channels':
107: if (empty($in) || !$perms->exists('jonah:news:' . $filter . ':' . $in)) {
108: return $perms->hasPermission('jonah:news:' . $filter, $GLOBALS['registry']->getAuth(), $permission);
109: } elseif (!is_array($in)) {
110: return $perms->hasPermission('jonah:news:' . $filter . ':' . $in, $GLOBALS['registry']->getAuth(), $permission);
111: } else {
112: foreach ($in as $key => $val) {
113: if ($perms->hasPermission('jonah:news:' . $filter . ':' . $val, $GLOBALS['registry']->getAuth(), $permission)) {
114: $out[$key] = $val;
115: }
116: }
117: }
118: break;
119:
120: case 'channels':
121: foreach ($in as $key => $val) {
122: $perm_name = Jonah::typeToPermName($val['channel_type']);
123: if ($perms->hasPermission('jonah:news:' . $perm_name, $GLOBALS['registry']->getAuth(), $permission) ||
124: $perms->hasPermission('jonah:news:' . $perm_name . ':' . $val['channel_id'], $GLOBALS['registry']->getAuth(), $permission)) {
125: $out[$key] = $in[$key];
126: }
127: }
128: break;
129:
130: default:
131: return $perms->hasPermission($filter, $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
132: }
133:
134: return $out;
135: }
136:
137: 138: 139: 140: 141: 142: 143:
144: static public function typeToPermName($type)
145: {
146: if ($type == Jonah::INTERNAL_CHANNEL) {
147: return 'internal_channels';
148: }
149: }
150:
151: 152: 153: 154: 155:
156: static public function getBodyTypes()
157: {
158: static $types = array();
159: if (!empty($types)) {
160: return $types;
161: }
162:
163: if (in_array('richtext', $GLOBALS['conf']['news']['story_types'])) {
164: $types['richtext'] = _("Rich Text");
165: }
166:
167: 168:
169: if (in_array('text', $GLOBALS['conf']['news']['story_types']) ||
170: empty($types)) {
171: $types['text'] = _("Text");
172: }
173:
174: return $types;
175: }
176:
177: 178: 179: 180: 181: 182:
183: static public function getDefaultBodyType()
184: {
185: $types = Jonah::getBodyTypes();
186: if (isset($types['text'])) {
187: return 'text';
188: } elseif (isset($types['richtext'])) {
189: return 'richtext';
190: }
191: 192:
193: return array_shift(array_keys($types));
194: }
195:
196: 197: 198: 199: 200: 201:
202: static public function getAvailableTypes()
203: {
204: $types = array();
205:
206: if (empty($GLOBALS['conf']['news']['enable'])) {
207: return $types;
208: }
209: if (in_array('internal', $GLOBALS['conf']['news']['enable'])) {
210: $types[Jonah::INTERNAL_CHANNEL] = _("Local Feed");
211: }
212: if (in_array('composite', $GLOBALS['conf']['news']['enable'])) {
213: $types[Jonah::COMPOSITE_CHANNEL] = _("Composite Feed");
214: }
215:
216: return $types;
217: }
218:
219: }