78cd27b3 |
1 | <?php |
2 | /******************************************************************************** |
ab02e8a9 |
3 | * banana/banana.inc.php : banana main file |
78cd27b3 |
4 | * -------------------------- |
5 | * |
6 | * This file is part of the banana distribution |
7 | * Copyright: See COPYING files that comes with this distribution |
8 | ********************************************************************************/ |
9 | |
1273e8f4 |
10 | require_once dirname(__FILE__) . '/text.func.inc.php'; |
11 | |
78cd27b3 |
12 | class Banana |
13 | { |
78cd27b3 |
14 | |
7972645b |
15 | ####### |
16 | # Configuration variables |
17 | ####### |
18 | |
19 | ### General ### |
20 | static public $profile = Array( 'signature' => '', |
21 | 'headers' => array('From' => 'Anonymous <anonymouse@example.com>'), |
22 | 'display' => 0, |
23 | 'lastnews' => 0, |
24 | 'locale' => 'fr_FR', |
25 | 'subscribe' => array(), |
26 | 'autoup' => 1); |
27 | static public $boxpattern; |
ed3717e5 |
28 | static public $withtabs = true; |
1273e8f4 |
29 | static public $mimeparts = array(); |
7972645b |
30 | |
31 | ### Spool ### |
32 | static public $spool_max = 3000; |
33 | static public $spool_tbefore = 5; |
34 | static public $spool_tafter = 5; |
35 | static public $spool_tmax = 50; |
e0f557df |
36 | static public $spool_boxlist = true; |
7972645b |
37 | |
38 | ### Message processing ### |
39 | static public $msgparse_headers = array('content-disposition', 'content-transfer-encoding', |
ab02e8a9 |
40 | 'content-type', 'content-id', 'date', 'followup-to', |
41 | 'from', 'message-id', 'newsgroups', 'organization', |
42 | 'references', 'subject', 'x-face', 'in-reply-to', |
43 | 'to', 'cc', 'reply-to'); |
4f6a209a |
44 | |
7972645b |
45 | ### Message display ### |
46 | static public $msgshow_headers = array('from', 'newsgroups', 'followup-to', 'to', 'cc', 'reply-to', |
47 | 'organization', 'date', 'references', 'in-reply-to'); |
1273e8f4 |
48 | static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed', |
49 | 'text/html', 'text/plain', 'text/enriched', 'text', 'message'); |
7972645b |
50 | static public $msgshow_xface = true; |
51 | static public $msgshow_wrap = 78; |
3be61f09 |
52 | static public $msgshow_externalimages = false; |
ed3717e5 |
53 | static public $msgshow_withthread = true; |
78cd27b3 |
54 | |
87514711 |
55 | /** Match an url |
bf791d69 |
56 | * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui") |
87514711 |
57 | * If it matches, return 3 main parts : |
58 | * \\1 and \\3 are delimiters |
59 | * \\2 is the url |
60 | * |
61 | * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches); |
62 | * $matches[1] = "[" |
63 | * $matches[2] = "http://www.polytechnique.org" |
64 | * $matches[3] = "]" |
65 | */ |
e0f557df |
66 | static public $msgshow_url = '(["\[])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]])?'; |
78cd27b3 |
67 | |
7972645b |
68 | ### Message edition ### |
69 | static public $msgedit_canattach = true; |
70 | static public $msgedit_maxfilesize = 100000; |
f12fdb59 |
71 | /** Global headers to use for messages |
a1937df3 |
72 | */ |
7972645b |
73 | static public $msgedit_headers = array('Mime-Version' => '1.0', 'User-Agent' => 'Banana @VERSION@'); |
bf791d69 |
74 | /** Mime type order for quoting |
75 | */ |
76 | static public $msgedit_mimeparts = array('multipart/report', 'multipart/mixed', 'text/plain', 'text/enriched', 'text/html', 'text', 'message'); |
77 | |
7972645b |
78 | ### Protocole ### |
a1937df3 |
79 | /** News serveur to use |
80 | */ |
7972645b |
81 | static public $nntp_host = 'news://localhost:119/'; |
ab02e8a9 |
82 | |
7972645b |
83 | static public $mbox_path = '/var/mail'; |
ab02e8a9 |
84 | |
7972645b |
85 | ### Debug ### |
ab02e8a9 |
86 | static public $debug_nntp = false; |
87 | static public $debug_smarty = false; |
88 | |
89 | |
7972645b |
90 | ####### |
91 | # Constants |
92 | ####### |
93 | |
ab02e8a9 |
94 | // Actions |
95 | const ACTION_BOX_NEEDED = 1; // mask |
96 | const ACTION_BOX_LIST = 2; |
97 | const ACTION_BOX_SUBS = 4; |
98 | const ACTION_MSG_LIST = 3; |
99 | const ACTION_MSG_READ = 5; |
100 | const ACTION_MSG_NEW = 9; |
101 | const ACTION_MSG_CANCEL = 17; |
102 | |
103 | // Box list view |
104 | const BOXES_ALL = 0; |
105 | const BOXES_SUB = 1; |
106 | const BOXES_NEW = 2; |
107 | |
108 | // Spool view mode |
109 | const SPOOL_ALL = 0; |
110 | const SPOOL_UNREAD = 1; |
111 | |
7972645b |
112 | |
113 | ####### |
114 | # Runtime variables |
115 | ####### |
116 | |
117 | static public $protocole = null; |
118 | static public $spool = null; |
119 | static public $message = null; |
120 | static public $page = null; |
121 | |
122 | static public $group = null; |
123 | static public $artid = null; |
124 | static public $action = null; |
125 | static public $part = null; |
126 | static public $first = null; |
127 | |
ab02e8a9 |
128 | /** Class parameters storage |
129 | */ |
130 | public $params; |
78cd27b3 |
131 | |
7972645b |
132 | |
133 | ####### |
134 | # Banana Implementation |
135 | ####### |
136 | |
ab02e8a9 |
137 | /** Build the instance of Banana |
138 | * This constructor only call \ref loadParams, connect to the server, and build the Smarty page |
139 | * @param protocole Protocole to use |
f6df9eb2 |
140 | */ |
ab02e8a9 |
141 | public function __construct($params = null, $protocole = 'NNTP', $pageclass = 'BananaPage') |
78cd27b3 |
142 | { |
ab02e8a9 |
143 | if (is_null($params)) { |
144 | $this->params = $_GET; |
1786dc36 |
145 | } else { |
ab02e8a9 |
146 | $this->params = $params; |
1786dc36 |
147 | } |
ab02e8a9 |
148 | $this->loadParams(); |
1786dc36 |
149 | |
ab02e8a9 |
150 | // connect to protocole handler |
ab02e8a9 |
151 | $classname = 'Banana' . $protocole; |
7972645b |
152 | if (!class_exists($classname)) { |
153 | Banana::load($protocole); |
154 | } |
ab02e8a9 |
155 | Banana::$protocole = new $classname(Banana::$group); |
78cd27b3 |
156 | |
ab02e8a9 |
157 | // build the page |
158 | if ($pageclass == 'BananaPage') { |
159 | Banana::load('page'); |
3c3d29bb |
160 | } |
ab02e8a9 |
161 | Banana::$page = new $pageclass; |
1273e8f4 |
162 | |
163 | $types = array('multipart/report' => _b_('Rapport d\'erreur'), |
164 | 'multipart/mixed' => _b_('Composition'), |
165 | 'text/html' => _b_('Texte formaté'), |
166 | 'text/plain' => _b_('Texte brut'), |
167 | 'text/enriched' => _b_('Texte enrichi'), |
168 | 'text' => _b_('Texte'), |
169 | 'message/rfc822' => _b_('Mail'), |
170 | 'message' => _b_('Message'), |
171 | 'source' => _b_('Source')); |
172 | Banana::$mimeparts = array_merge($types, Banana::$mimeparts); |
ab02e8a9 |
173 | } |
78cd27b3 |
174 | |
ab02e8a9 |
175 | /** Fill state vars (Banana::$group, Banana::$artid, Banana::$action, Banana;:$part, Banana::$first) |
176 | */ |
177 | protected function loadParams() |
178 | { |
179 | Banana::$group = isset($this->params['group']) ? $this->params['group'] : null; |
180 | Banana::$artid = isset($this->params['artid']) ? $this->params['artid'] : null; |
181 | Banana::$first = isset($this->params['first']) ? $this->params['first'] : null; |
182 | Banana::$part = isset($this->params['part']) ? $this->params['part'] : 'text'; |
183 | |
184 | // Look for the action to execute |
185 | if (is_null(Banana::$group)) { |
ded3974d |
186 | if (isset($this->params['action']) && $this->params['action'] == 'subscribe') { |
ab02e8a9 |
187 | Banana::$action = Banana::ACTION_BOX_SUBS; |
78cd27b3 |
188 | } else { |
ab02e8a9 |
189 | Banana::$action = Banana::ACTION_BOX_LIST; |
78cd27b3 |
190 | } |
ab02e8a9 |
191 | return; |
192 | } |
193 | $action = isset($this->params['action']) ? $this->params['action'] : null; |
194 | if (is_null(Banana::$artid)) { |
195 | if ($action == 'new') { |
196 | Banana::$action = Banana::ACTION_MSG_NEW; |
197 | } else { |
198 | Banana::$action = Banana::ACTION_MSG_LIST; |
7a0e2710 |
199 | } |
ab02e8a9 |
200 | return; |
201 | } |
202 | switch ($action) { |
203 | case 'new': |
204 | Banana::$action = Banana::ACTION_MSG_NEW; |
205 | return; |
206 | case 'cancel': |
207 | Banana::$action = Banana::ACTION_MSG_CANCEL; |
208 | return; |
209 | default: |
210 | Banana::$action = Banana::ACTION_MSG_READ; |
78cd27b3 |
211 | } |
212 | } |
213 | |
ab02e8a9 |
214 | /** Run Banana |
215 | * This function need user profile to be initialised |
216 | */ |
217 | public function run() |
78cd27b3 |
218 | { |
ab02e8a9 |
219 | // Configure locales |
220 | setlocale(LC_ALL, Banana::$profile['locale']); |
78cd27b3 |
221 | |
ab02e8a9 |
222 | // Check if the state is valid |
223 | if (Banana::$protocole->lastErrNo()) { |
d8d416c4 |
224 | return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '<br />' |
ab02e8a9 |
225 | . Banana::$protocole->lastError()); |
226 | } |
227 | if (!Banana::$protocole->isValid()) { |
228 | return Banana::$page->kill(_b_('Connexion non-valide')); |
229 | } |
230 | if (Banana::$action & Banana::ACTION_BOX_NEEDED) { |
7972645b |
231 | if(Banana::$boxpattern && !preg_match('/' . Banana::$boxpattern . '/i', $group)) { |
ab02e8a9 |
232 | Banana::$page->setPage('group'); |
d8d416c4 |
233 | return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder")); |
ab02e8a9 |
234 | } |
235 | } |
78cd27b3 |
236 | |
ab02e8a9 |
237 | // Dispatch to the action handlers |
238 | switch (Banana::$action) { |
239 | case Banana::ACTION_BOX_SUBS: |
240 | $error = $this->action_subscribe(); |
241 | break; |
242 | case Banana::ACTION_BOX_LIST: |
243 | $error = $this->action_listBoxes(); |
244 | break; |
245 | case Banana::ACTION_MSG_LIST: |
246 | $error = $this->action_showThread(Banana::$group, Banana::$first); |
247 | break; |
248 | case Banana::ACTION_MSG_READ: |
249 | $error = $this->action_showMessage(Banana::$group, Banana::$artid, Banana::$part); |
250 | break; |
251 | case Banana::ACTION_MSG_NEW: |
252 | $error = $this->action_newMessage(Banana::$group, Banana::$artid); |
253 | break; |
254 | case Banana::ACTION_MSG_CANCEL: |
255 | $error = $this->action_cancelMessage(Banana::$group, Banana::$artid); |
256 | break; |
257 | default: |
d8d416c4 |
258 | $error = _b_("L'action demandée n'est pas supportée par Banana"); |
ab02e8a9 |
259 | } |
260 | |
261 | // Generate the page |
262 | if (is_string($error)) { |
263 | return Banana::$page->kill($error); |
264 | } |
265 | return Banana::$page->run(); |
78cd27b3 |
266 | } |
267 | |
a20df265 |
268 | /** Return the CSS code to include in the headers |
269 | */ |
270 | public function css() |
271 | { |
272 | return Banana::$page->css; |
273 | } |
274 | |
ab02e8a9 |
275 | /**************************************************************************/ |
276 | /* actions */ |
277 | /**************************************************************************/ |
278 | protected function action_saveSubs($groups) |
78cd27b3 |
279 | { |
ab02e8a9 |
280 | Banana::$profile['subscribe'] = $groups; |
281 | return true; |
78cd27b3 |
282 | } |
283 | |
ab02e8a9 |
284 | protected function action_subscribe() |
78cd27b3 |
285 | { |
ab02e8a9 |
286 | Banana::$page->setPage('subscribe'); |
287 | if (isset($_POST['validsubs'])) { |
288 | $this->action_saveSubs(array_keys($_POST['subscribe'])); |
289 | Banana::$page->redirect(); |
856dc84a |
290 | } |
ab02e8a9 |
291 | $groups = Banana::$protocole->getBoxList(Banana::BOXES_ALL); |
292 | Banana::$page->assign('groups', $groups); |
293 | return true; |
78cd27b3 |
294 | } |
295 | |
ab02e8a9 |
296 | protected function action_listBoxes() |
7a0e2710 |
297 | { |
ab02e8a9 |
298 | Banana::$page->setPage('forums'); |
299 | $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); |
300 | $newgroups = Banana::$protocole->getBoxList(Banana::BOXES_NEW, Banana::$profile['lastnews'], true); |
301 | Banana::$page->assign('groups', $groups); |
302 | Banana::$page->assign('newgroups', $newgroups); |
303 | return true; |
7a0e2710 |
304 | } |
305 | |
ab02e8a9 |
306 | protected function action_showThread($group, $first) |
78cd27b3 |
307 | { |
ab02e8a9 |
308 | Banana::$page->setPage('thread'); |
309 | if (!$this->loadSpool($group)) { |
310 | return _b_('Impossible charger la liste des messages de ') . $group; |
78cd27b3 |
311 | } |
e0f557df |
312 | if (Banana::$spool_boxlist) { |
313 | $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); |
314 | Banana::$page->assign('groups', $groups); |
315 | } |
7972645b |
316 | Banana::$page->assign('msgbypage', Banana::$spool_tmax); |
ab02e8a9 |
317 | return true; |
78cd27b3 |
318 | } |
319 | |
ab02e8a9 |
320 | protected function action_showMessage($group, $artid, $partid = 'text') |
78cd27b3 |
321 | { |
ab02e8a9 |
322 | Banana::$page->setPage('message'); |
9bc195d6 |
323 | $istext = $partid == 'text' || $partid == 'source' |
25c20c41 |
324 | || preg_match('!^[-a-z0-9_]+/[-a-z0-9_]+$!', $partid); |
9bc195d6 |
325 | if ($istext) { |
ab02e8a9 |
326 | $this->loadSpool($group); |
327 | } |
328 | $msg =& $this->loadMessage($group, $artid); |
329 | if (is_null($msg)) { |
330 | $this->loadSpool($group); |
331 | $this->removeMessage($group, $artid); |
d8d416c4 |
332 | return _b_('Le message demandé n\'existe pas. Il est possible qu\'il ait été annulé'); |
ab02e8a9 |
333 | } |
334 | if ($partid == 'xface') { |
335 | $msg->getXFace(); |
336 | exit; |
9bc195d6 |
337 | } elseif (!$istext) { |
ab02e8a9 |
338 | $part = $msg->getPartById($partid); |
339 | if (!is_null($part)) { |
340 | $part->send(true); |
52cafcf1 |
341 | } |
ab02e8a9 |
342 | $part = $msg->getFile($partid); |
343 | if (!is_null($part)) { |
344 | $part->send(); |
78cd27b3 |
345 | } |
ab02e8a9 |
346 | exit; |
9bc195d6 |
347 | } elseif ($partid == 'text') { |
1273e8f4 |
348 | $partid = null; |
349 | Banana::$page->assign('body', $msg->getFormattedBody($partid)); |
9bc195d6 |
350 | } elseif ($partid == 'source') { |
b188e462 |
351 | $text = Banana::$protocole->getMessageSource($artid); |
352 | if (!is_utf8($text)) { |
353 | $text = utf8_encode($text); |
354 | } |
355 | Banana::$page->assign('body', '<pre>' . banana_htmlentities($text) . '</pre>'); |
9bc195d6 |
356 | } else { |
357 | Banana::$page->assign('body', $msg->getFormattedBody($partid)); |
78cd27b3 |
358 | } |
9bc195d6 |
359 | |
7972645b |
360 | if (Banana::$profile['autoup']) { |
361 | Banana::$spool->markAsRead($artid); |
362 | } |
e0f557df |
363 | if (Banana::$spool_boxlist) { |
364 | $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); |
365 | Banana::$page->assign('groups', $groups); |
366 | } |
ab02e8a9 |
367 | Banana::$page->assign_by_ref('message', $msg); |
7972645b |
368 | Banana::$page->assign('headers', Banana::$msgshow_headers); |
1273e8f4 |
369 | Banana::$page->assign('type', $partid); |
ab02e8a9 |
370 | return true; |
78cd27b3 |
371 | } |
372 | |
ab02e8a9 |
373 | protected function action_newMessage($group, $artid) |
78cd27b3 |
374 | { |
ab02e8a9 |
375 | Banana::$page->setPage('new'); |
376 | if (!Banana::$protocole->canSend()) { |
377 | return _b_('Vous n\'avez pas le droit de poster'); |
378 | } |
379 | $hdrs = Banana::$protocole->requestedHeaders(); |
380 | $headers = array(); |
381 | foreach ($hdrs as $header) { |
382 | $headers[$header] = array('name' => BananaMessage::translateHeaderName($header)); |
7972645b |
383 | if (isset(Banana::$profile['headers'][$header])) { |
384 | $headers[$header]['fixed'] = Banana::$profile['headers'][$header]; |
78cd27b3 |
385 | } |
386 | } |
ab02e8a9 |
387 | if (isset($_POST['sendmessage'])) { |
388 | $hdr_values = array(); |
389 | foreach ($hdrs as $header) { |
390 | $hdr_values[$header] = isset($headers[$header]['fixed']) ? $headers[$header]['fixed'] : @$_POST[$header]; |
f6df9eb2 |
391 | } |
ab02e8a9 |
392 | if ($artid) { |
393 | $old =& $this->loadMessage($group, $artid); |
394 | $hdr_values['References'] = $old->getHeaderValue('references') . $old->getHeaderValue('message-id'); |
856dc84a |
395 | } |
ab02e8a9 |
396 | $msg = null; |
397 | if (empty($hdr_values['Subject'])) { |
398 | Banana::$page->trig(_b_('Le message doit avoir un sujet')); |
7972645b |
399 | } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment'])) { |
ab02e8a9 |
400 | $uploaded = $_FILES['attachment']; |
401 | if (!is_uploaded_file($uploaded['tmp_name'])) { |
d8d416c4 |
402 | Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier')); |
ab02e8a9 |
403 | } else { |
404 | $msg = BananaMessage::newMessage($hdr_values, $_POST['body'], $uploaded); |
405 | } |
406 | } else { |
407 | $msg = BananaMessage::newMessage($hdr_values, $_POST['body']); |
408 | } |
409 | if (!is_null($msg)) { |
410 | if (Banana::$protocole->send($msg)) { |
411 | Banana::$page->redirect(array('group' => $group, 'artid' => $artid)); |
412 | } |
413 | Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />' |
414 | . Banana::$protocole->lastError()); |
f6df9eb2 |
415 | } |
78cd27b3 |
416 | } else { |
ab02e8a9 |
417 | if (!is_null($artid)) { |
418 | $msg =& $this->loadMessage($group, $artid); |
d8d416c4 |
419 | $body = $msg->getSender() . _b_(' a écrit :') . "\n" . $msg->quote(); |
ab02e8a9 |
420 | $subject = $msg->getHeaderValue('subject'); |
421 | $headers['Subject']['user'] = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $subject); |
422 | $target = $msg->getHeaderValue($hdrs['reply']); |
423 | if (empty($target)) { |
424 | $target = $group; |
425 | } |
426 | $headers[$hdrs['dest']]['user'] =& $target; |
427 | } else { |
428 | $body = ''; |
429 | $headers[$hdrs['dest']]['user'] = $group; |
856dc84a |
430 | } |
7972645b |
431 | if (Banana::$profile['signature']) { |
432 | $body .= "\n\n-- \n" . Banana::$profile['signature']; |
ab02e8a9 |
433 | } |
434 | Banana::$page->assign('body', $body); |
78cd27b3 |
435 | } |
ab02e8a9 |
436 | |
7972645b |
437 | Banana::$page->assign('maxfilesize', Banana::$msgedit_maxfilesize); |
438 | Banana::$page->assign('can_attach', Banana::$msgedit_canattach); |
ab02e8a9 |
439 | Banana::$page->assign('headers', $headers); |
856dc84a |
440 | return true; |
78cd27b3 |
441 | } |
442 | |
ab02e8a9 |
443 | protected function action_cancelMessage($group, $artid) |
78cd27b3 |
444 | { |
ab02e8a9 |
445 | Banana::$page->setPage('cancel'); |
446 | $msg =& $this->loadMessage($group, $artid); |
447 | if (!$msg->canCancel()) { |
448 | return _b_('Vous n\'avez pas les droits suffisants pour supprimer ce message'); |
449 | } |
450 | if (isset($_POST['cancel'])) { |
451 | $this->loadSpool($group); |
452 | $ndx = Banana::$spool->getNdX($id) - 1; |
453 | if (!Banana::$protocole->cancel($msg)) { |
454 | return _b_('Une erreur s\'est produite lors de l\'annulation du message :') . '<br />' |
455 | . Banana::$protocole->lastError(); |
456 | } |
457 | if ($ndx < 50) { |
458 | $ndx = 0; |
459 | } |
460 | $this->removeMessage($group, $artid); |
461 | Banana::$page->redirect(Array('group' => $group, 'first' => $ndx)); |
856dc84a |
462 | } |
d759a2ba |
463 | |
ab02e8a9 |
464 | Banana::$page->assign_by_ref('message', $msg); |
d759a2ba |
465 | Banana::$page->assign('body', $msg->getFormattedBody()); |
466 | Banana::$page->assign('headers', Banana::$msgshow_headers); |
856dc84a |
467 | return true; |
78cd27b3 |
468 | } |
469 | |
ab02e8a9 |
470 | /**************************************************************************/ |
a40f3908 |
471 | /* Spoolgen functions */ |
472 | /**************************************************************************/ |
473 | |
474 | private function checkErrors() |
475 | { |
476 | if (Banana::$protocole->lastErrno()) { |
477 | echo "\nL'erreur suivante s'est produite : " |
478 | . Banana::$protocole->lastErrno() . " " |
479 | . Banana::$protocole->lastError() . "\n"; |
480 | return false; |
481 | } |
482 | return true; |
483 | } |
484 | |
485 | static public function createAllSpool(array $protos) |
486 | { |
487 | foreach ($protos as $proto) { |
488 | $banana = new Banana(array(), $proto); |
489 | |
490 | if (!$banana->checkErrors()) { |
491 | continue; |
492 | } |
493 | $groups = Banana::$protocole->getBoxList(); |
494 | if (!$banana->checkErrors()) { |
495 | continue; |
496 | } |
497 | |
498 | print "** $proto **\n"; |
499 | foreach (array_keys($groups) as $g) { |
500 | print "Generating spool for $g : "; |
501 | Banana::$group = $g; |
502 | $spool = $banana->loadSpool($g); |
503 | if (!$banana->checkErrors()) { |
504 | break; |
505 | } |
506 | print "done.\n"; |
507 | unset($spool); |
508 | } |
509 | print "\n"; |
510 | } |
511 | } |
512 | |
513 | /**************************************************************************/ |
ab02e8a9 |
514 | /* Private functions */ |
515 | /**************************************************************************/ |
516 | |
916e4a56 |
517 | protected function loadSpool($group) |
78cd27b3 |
518 | { |
ab02e8a9 |
519 | Banana::load('spool'); |
520 | if (!Banana::$spool || Banana::$spool->group != $group) { |
e0f557df |
521 | $clean = false; |
ab02e8a9 |
522 | if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) { |
523 | Banana::$spool = unserialize($_SESSION['banana_spool']); |
7b98ea62 |
524 | $clean = @(Banana::$profile['lastnews'] != $_SESSION['banana_lastnews']); |
a5980eae |
525 | } else { |
526 | unset($_SESSION['banana_message']); |
527 | unset($_SESSION['banana_artid']); |
528 | unset($_SESSION['banana_showhdr']); |
7972645b |
529 | } |
7b98ea62 |
530 | BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup'] || $clean); |
ab02e8a9 |
531 | $_SESSION['banana_group'] = $group; |
7972645b |
532 | if (!Banana::$profile['display']) { |
533 | $_SESSION['banana_spool'] = serialize(Banana::$spool); |
7b98ea62 |
534 | $_SESSION['banana_lastnews'] = Banana::$profile['lastnews']; |
7972645b |
535 | } |
ab02e8a9 |
536 | Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL); |
78cd27b3 |
537 | } |
ab02e8a9 |
538 | return true; |
78cd27b3 |
539 | } |
540 | |
916e4a56 |
541 | protected function &loadMessage($group, $artid) |
78cd27b3 |
542 | { |
ab02e8a9 |
543 | Banana::load('message'); |
544 | if ($group == @$_SESSION['banana_group'] && $artid == @$_SESSION['banana_artid'] |
545 | && isset($_SESSION['banana_message'])) { |
546 | $message = unserialize($_SESSION['banana_message']); |
7972645b |
547 | Banana::$msgshow_headers = $_SESSION['banana_showhdr']; |
ab02e8a9 |
548 | } else { |
549 | $message = Banana::$protocole->getMessage($artid); |
550 | $_SESSION['banana_group'] = $group; |
551 | $_SESSION['banana_artid'] = $artid; |
552 | $_SESSION['banana_message'] = serialize($message); |
7972645b |
553 | $_SESSION['banana_showhdr'] = Banana::$msgshow_headers; |
ab02e8a9 |
554 | } |
555 | Banana::$message =& $message; |
556 | return $message; |
78cd27b3 |
557 | } |
d28aa62d |
558 | |
916e4a56 |
559 | protected function removeMessage($group, $artid) |
d28aa62d |
560 | { |
ab02e8a9 |
561 | Banana::$spool->delId($artid); |
562 | if ($group == $_SESSION['banana_group']) { |
7972645b |
563 | if (!Banana::$profile['display']) { |
564 | $_SESSION['banana_spool'] = serialize(Banana::$spool); |
7b3d2efb |
565 | } |
ab02e8a9 |
566 | if ($artid == $_SESSION['banana_artid']) { |
567 | unset($_SESSION['banana_message']); |
568 | unset($_SESSION['banana_showhdr']); |
569 | unset($_SESSION['banana_artid']); |
d28aa62d |
570 | } |
d28aa62d |
571 | } |
ab02e8a9 |
572 | return true; |
d28aa62d |
573 | } |
f12fdb59 |
574 | |
ab02e8a9 |
575 | static private function load($file) |
f12fdb59 |
576 | { |
ab02e8a9 |
577 | $file = strtolower($file) . '.inc.php'; |
578 | if (!@include_once dirname(__FILE__) . "/$file") { |
579 | require_once $file; |
580 | } |
f12fdb59 |
581 | } |
78cd27b3 |
582 | } |
583 | |
d8d416c4 |
584 | // vim:set et sw=4 sts=4 ts=4 enc=utf-8: |
78cd27b3 |
585 | ?> |