34ae838edc9b37c0aa1ba5e31caae16e0ef6c59c
[banana.git] / banana / banana.inc.php.in
1 <?php
2 /********************************************************************************
3 * banana/banana.inc.php : banana main file
4 * --------------------------
5 *
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
9
10 require_once dirname(__FILE__) . '/text.func.inc.php';
11
12 class Banana
13 {
14
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.UTF-8',
25 'subscribe' => array(),
26 'autoup' => 1);
27 static public $boxpattern;
28 static public $withtabs = true;
29 static public $baseurl = null;
30 static public $mimeparts = array();
31
32 ### Spool ###
33 static public $spool_root = '/var/spool/banana';
34 static public $spool_max = 3000;
35 static public $spool_tbefore = 5;
36 static public $spool_tafter = 5;
37 static public $spool_tmax = 50;
38 static public $spool_boxlist = true;
39
40 ### Message processing ###
41 static public $msgparse_headers = array('content-disposition', 'content-transfer-encoding',
42 'content-type', 'content-id', 'date', 'followup-to',
43 'from', 'message-id', 'newsgroups', 'organization',
44 'references', 'subject', 'x-face', 'in-reply-to',
45 'to', 'cc', 'reply-to');
46
47 ### Message display ###
48 static public $msgshow_headers = array('from', 'newsgroups', 'followup-to', 'to', 'cc', 'reply-to',
49 'organization', 'date', 'references', 'in-reply-to');
50 static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed',
51 'text/html', 'text/plain', 'text/enriched', 'text', 'message');
52 static public $msgshow_xface = true;
53 static public $msgshow_wrap = 80;
54 static public $msgshow_externalimages = false;
55 static public $msgshow_hasextimages = false;
56 static public $msgshow_withthread = true;
57 static public $msgshow_javascript = true;
58
59 /** Match an url
60 * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui")
61 * If it matches, return 3 main parts :
62 * \\1 and \\3 are delimiters
63 * \\2 is the url
64 *
65 * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches);
66 * $matches[1] = "["
67 * $matches[2] = "http://www.polytechnique.org"
68 * $matches[3] = "]"
69 */
70 static public $msgshow_url = '(["\[\<])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!\:]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]\>])?';
71
72 ### Message edition ###
73 static public $msgedit_canattach = true;
74 static public $msgedit_maxfilesize = 100000;
75 /** Global headers to use for messages
76 */
77 static public $msgedit_headers = array('Mime-Version' => '1.0', 'User-Agent' => 'Banana @VERSION@');
78 /** Mime type order for quoting
79 */
80 static public $msgedit_mimeparts = array('multipart/report', 'multipart/mixed', 'text/plain', 'text/enriched', 'text/html', 'text', 'message');
81
82 ### Feed configuration ###
83 static public $feed_active = true;
84 static public $feed_format = 'rss2';
85 static public $feed_updateOnDemand = false; // Update the feed each time sbd check it
86 static public $feed_copyright = null; // Global copyright informations
87 static public $feed_generator = 'Banana @VERSION@'; // Feed generator
88 static public $feed_email = null; // Admin e-mail
89 static public $feed_namePrefix = 'Banana :: ';
90 static public $feed_size = 15; // Number of messages in the feed
91
92 ### Protocole ###
93 /** News serveur to use
94 */
95 static public $nntp_host = 'news://localhost:119/';
96
97 static public $mbox_path = '/var/mail';
98 static public $mbox_helper = './mbox-helper';
99
100 ### Debug ###
101 static public $debug_nntp = false;
102 static public $debug_mbox = false;
103 static public $debug_smarty = false;
104
105
106 #######
107 # Constants
108 #######
109
110 // Actions
111 const ACTION_BOX_NEEDED = 1; // mask
112 const ACTION_BOX_LIST = 2;
113 const ACTION_BOX_SUBS = 4;
114 const ACTION_BOX_FEED = 8;
115 const ACTION_MSG_LIST = 3;
116 const ACTION_MSG_READ = 5;
117 const ACTION_MSG_NEW = 9;
118 const ACTION_MSG_CANCEL = 17;
119 const ACTION_MSG_IMAGES = 33;
120
121 // Box list view
122 const BOXES_ALL = 0;
123 const BOXES_SUB = 1;
124 const BOXES_NEW = 2;
125
126 // Spool view mode
127 const SPOOL_ALL = 0;
128 const SPOOL_UNREAD = 1;
129
130
131 #######
132 # Runtime variables
133 #######
134
135 static public $protocole = null;
136 static public $spool = null;
137 static public $message = null;
138 static public $page = null;
139
140 static public $group = null;
141 static public $artid = null;
142 static public $action = null;
143 static public $part = null;
144 static public $first = null;
145
146 /** Class parameters storage
147 */
148 public $params;
149
150
151 #######
152 # Banana Implementation
153 #######
154
155 /** Build the instance of Banana
156 * This constructor only call \ref loadParams, connect to the server, and build the Smarty page
157 * @param protocole Protocole to use
158 */
159 public function __construct($params = null, $protocole = 'NNTP', $pageclass = 'BananaPage')
160 {
161 if (is_null($params)) {
162 $this->params = $_GET;
163 } else {
164 $this->params = $params;
165 }
166 $this->loadParams();
167
168 // connect to protocole handler
169 $classname = 'Banana' . $protocole;
170 if (!class_exists($classname)) {
171 Banana::load($protocole);
172 }
173 Banana::$protocole = new $classname(Banana::$group);
174
175 // build the page
176 if ($pageclass == 'BananaPage') {
177 Banana::load('page');
178 }
179 Banana::$page = new $pageclass;
180 $types = array('multipart/report' => _b_('Rapport d\'erreur'),
181 'multipart/mixed' => _b_('Composition'),
182 'text/html' => _b_('Texte formaté'),
183 'text/plain' => _b_('Texte brut'),
184 'text/enriched' => _b_('Texte enrichi'),
185 'text' => _b_('Texte'),
186 'message/rfc822' => _b_('Mail'),
187 'message' => _b_('Message'),
188 'source' => _b_('Source'));
189 Banana::$mimeparts = array_merge($types, Banana::$mimeparts);
190 }
191
192 /** Fill state vars (Banana::$group, Banana::$artid, Banana::$action, Banana;:$part, Banana::$first)
193 */
194 protected function loadParams()
195 {
196 foreach ($this->params as &$value) {
197 if ($value === "") {
198 $value = null;
199 }
200 }
201 Banana::$group = isset($this->params['group']) ? $this->params['group'] : null;
202 Banana::$artid = isset($this->params['artid']) ? $this->params['artid'] : null;
203 Banana::$first = isset($this->params['first']) ? $this->params['first'] : null;
204 Banana::$part = isset($this->params['part']) ? $this->params['part'] : 'text';
205
206 $action = @$this->params['action'];
207 if ($action == 'rss' || $action == 'rss2' || $action == 'atom') {
208 if ($action == 'rss') {
209 $action = 'rss2';
210 }
211 Banana::$feed_format = $action;
212 Banana::$action = Banana::ACTION_BOX_FEED;
213 return;
214 }
215
216 // Look for the action to execute
217 if (is_null(Banana::$group)) {
218 if ($action == 'subscribe') {
219 Banana::$action = Banana::ACTION_BOX_SUBS;
220 } else {
221 Banana::$action = Banana::ACTION_BOX_LIST;
222 }
223 return;
224 }
225
226 if (is_null(Banana::$artid)) {
227 if ($action == 'new') {
228 Banana::$action = Banana::ACTION_MSG_NEW;
229 } else {
230 Banana::$action = Banana::ACTION_MSG_LIST;
231 }
232 return;
233 }
234 switch ($action) {
235 case 'new':
236 Banana::$action = Banana::ACTION_MSG_NEW;
237 return;
238 case 'cancel':
239 Banana::$action = Banana::ACTION_MSG_CANCEL;
240 return;
241 case 'showext':
242 Banana::$action = Banana::ACTION_MSG_IMAGES;
243 return;
244 default:
245 Banana::$action = Banana::ACTION_MSG_READ;
246 }
247 }
248
249 /** Run Banana
250 * This function need user profile to be initialised
251 */
252 public function run()
253 {
254 // Configure locales
255 setlocale(LC_ALL, Banana::$profile['locale']);
256
257 // Check if the state is valid
258 if (Banana::$protocole->lastErrNo()) {
259 return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '<br />'
260 . Banana::$protocole->lastError());
261 }
262 if (!Banana::$protocole->isValid()) {
263 return Banana::$page->kill(_b_('Connexion non-valide'));
264 }
265 if (Banana::$action & Banana::ACTION_BOX_NEEDED) {
266 if(Banana::$boxpattern && !preg_match('/' . Banana::$boxpattern . '/i', Banana::$group)) {
267 Banana::$page->setPage('group');
268 return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder"));
269 }
270 }
271
272 // Dispatch to the action handlers
273 switch (Banana::$action) {
274 case Banana::ACTION_BOX_SUBS:
275 $error = $this->action_subscribe();
276 break;
277 case Banana::ACTION_BOX_LIST:
278 $error = $this->action_listBoxes();
279 break;
280 case Banana::ACTION_BOX_FEED:
281 $this->action_feed(); // generate its own xml
282 break;
283 case Banana::ACTION_MSG_LIST:
284 $error = $this->action_showThread(Banana::$group, Banana::$first);
285 break;
286 case Banana::ACTION_MSG_IMAGES:
287 Banana::$msgshow_externalimages = true;
288 case Banana::ACTION_MSG_READ:
289 $error = $this->action_showMessage(Banana::$group, Banana::$artid, Banana::$part);
290 break;
291 case Banana::ACTION_MSG_NEW:
292 $error = $this->action_newMessage(Banana::$group, Banana::$artid);
293 break;
294 case Banana::ACTION_MSG_CANCEL:
295 $error = $this->action_cancelMessage(Banana::$group, Banana::$artid);
296 break;
297 default:
298 $error = _b_("L'action demandée n'est pas supportée par Banana");
299 }
300
301 // Generate the page
302 if (is_string($error)) {
303 return Banana::$page->kill($error);
304 }
305 return Banana::$page->run();
306 }
307
308 /** Build and post a new message
309 * @return postid (or -1 if the message has not been found)
310 */
311 public function post($dest, $reply, $subject, $body)
312 {
313 $hdrs = Banana::$protocole->requestedHeaders();
314 $headers = Banana::$profile['headers'];
315 $headers[$hdrs['dest']] = $dest;
316 if ($reply) {
317 $headers[$hdrs['reply']] = $reply;
318 }
319 $headers['Subject'] = $subject;
320 $msg = BananaMessage::newMessage($headers, $body);
321 if (Banana::$protocole->send($msg)) {
322 Banana::$group = ($reply ? $reply : $dest);
323 $this->loadSpool(Banana::$group);
324 return Banana::$spool->getPostId($subject);
325 }
326 return -1;
327 }
328
329 /** Return the CSS code to include in the headers
330 */
331 public function css()
332 {
333 return Banana::$page->css;
334 }
335
336 /** Return the Link to the feed of the page
337 */
338 public function feed()
339 {
340 if (!Banana::$feed_active) {
341 return null;
342 }
343 return Banana::$page->makeURL(array('group' => Banana::$group, 'action' => Banana::$feed_format));
344 }
345
346 /** Return the execution backtrace of the current BananaProtocole
347 */
348 public function backtrace()
349 {
350 if (Banana::$protocole) {
351 return Banana::$protocole->backtrace();
352 }
353 return null;
354 }
355
356 /**************************************************************************/
357 /* actions */
358 /**************************************************************************/
359 protected function action_saveSubs($groups)
360 {
361 Banana::$profile['subscribe'] = $groups;
362 return true;
363 }
364
365 protected function action_subscribe()
366 {
367 Banana::$page->setPage('subscribe');
368 if (isset($_POST['validsubs'])) {
369 $this->action_saveSubs(array_keys($_POST['subscribe']));
370 Banana::$page->redirect();
371 }
372 $groups = Banana::$protocole->getBoxList(Banana::BOXES_ALL);
373 Banana::$page->assign('groups', $groups);
374 return true;
375 }
376
377 protected function action_listBoxes()
378 {
379 Banana::$page->setPage('forums');
380 $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
381 Banana::$page->assign('groups', $groups);
382 if (empty(Banana::$profile['subscribe']) || Banana::$profile['lastnews']) {
383 $newgroups = Banana::$protocole->getBoxList(Banana::BOXES_NEW, Banana::$profile['lastnews'], true);
384 Banana::$page->assign('newgroups', $newgroups);
385 }
386 return true;
387 }
388
389 protected function action_feed()
390 {
391 Banana::load('feed');
392 if (Banana::$group) {
393 if (Banana::$feed_updateOnDemand) {
394 $this->loadSpool(Banana::$group);
395 }
396 $feed =& BananaFeed::getFeed();
397 $feed->toXML();
398 }
399 if (Banana::$profile['subscribe']) {
400 $subfeed = null;
401 foreach (Banana::$profile['subscribe'] as $group) {
402 Banana::$group = $group;
403 if (Banana::$feed_updateOnDemand) {
404 $this->loadSpool($group);
405 }
406 $feed =& BananaFeed::getFeed();
407 $subfeed =& BananaFeed::merge($subfeed, $feed, _b_('Abonnements'), _b_('Mes abonnements Banana'));
408 }
409 $subfeed->toXML();
410 }
411 Banana::$page->feed();
412 }
413
414 protected function action_showThread($group, $first)
415 {
416 Banana::$page->setPage('thread');
417 if (!$this->loadSpool($group)) {
418 return _b_('Impossible charger la liste des messages de ') . $group;
419 }
420 if (Banana::$spool_boxlist) {
421 $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
422 Banana::$page->assign('groups', $groups);
423 }
424 Banana::$page->assign('msgbypage', Banana::$spool_tmax);
425 return true;
426 }
427
428 protected function action_showMessage($group, $artid, $partid = 'text')
429 {
430 Banana::$page->setPage('message');
431 $istext = $partid == 'text' || $partid == 'source'
432 || preg_match('!^[-a-z0-9_]+/[-a-z0-9_]+$!', $partid);
433 if ($istext) {
434 $this->loadSpool($group);
435 }
436 $msg =& $this->loadMessage($group, $artid);
437 if (is_null($msg)) {
438 $this->loadSpool($group);
439 $this->removeMessage($group, $artid);
440 return _b_('Le message demandé n\'existe pas. Il est possible qu\'il ait été annulé');
441 }
442 if ($partid == 'xface') {
443 $msg->getXFace();
444 exit;
445 } elseif (!$istext) {
446 $part = $msg->getPartById($partid);
447 if (!is_null($part)) {
448 $part->send(true);
449 }
450 $part = $msg->getFile($partid);
451 if (!is_null($part)) {
452 $part->send();
453 }
454 exit;
455 } elseif ($partid == 'text') {
456 $partid = null;
457 Banana::$page->assign('body', $msg->getFormattedBody($partid));
458 } elseif ($partid == 'source') {
459 $text = Banana::$protocole->getMessageSource($artid);
460 if (!is_utf8($text)) {
461 $text = utf8_encode($text);
462 }
463 Banana::$page->assign('body', '<pre>' . banana_htmlentities($text) . '</pre>');
464 } else {
465 Banana::$page->assign('body', $msg->getFormattedBody($partid));
466 }
467
468 if (Banana::$profile['autoup']) {
469 Banana::$spool->markAsRead($artid);
470 }
471 if (Banana::$spool_boxlist) {
472 $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
473 Banana::$page->assign('groups', $groups);
474 }
475 Banana::$page->assign_by_ref('message', $msg);
476 Banana::$page->assign('extimages', Banana::$msgshow_hasextimages);
477 Banana::$page->assign('headers', Banana::$msgshow_headers);
478 Banana::$page->assign('type', $partid);
479 return true;
480 }
481
482 protected function action_newMessage($group, $artid)
483 {
484 Banana::$page->setPage('new');
485 if (!Banana::$protocole->canSend()) {
486 return _b_('Vous n\'avez pas le droit de poster');
487 }
488 $hdrs = Banana::$protocole->requestedHeaders();
489 $headers = array();
490 foreach ($hdrs as $header) {
491 $headers[$header] = array('name' => BananaMessage::translateHeaderName($header));
492 if (isset(Banana::$profile['headers'][$header])) {
493 $headers[$header]['fixed'] = Banana::$profile['headers'][$header];
494 }
495 }
496 if (isset($_POST['sendmessage'])) {
497 $hdr_values = array();
498 foreach ($hdrs as $header) {
499 $hdr_values[$header] = isset($headers[$header]['fixed']) ? $headers[$header]['fixed'] : @$_POST[$header];
500 if (!is_utf8($hdr_values[$header])) {
501 $hdr_values[$header] = utf8_encode($hdr_values[$header]);
502 }
503 if ($headers != 'Subject') {
504 $hdr_values[$header] = str_replace(', ', ',', $hdr_values[$header]);
505 }
506 }
507 if (!is_null($artid)) {
508 $old =& $this->loadMessage($group, $artid);
509 $hdr_values['References'] = $old->getHeaderValue('references') . ' ' . $old->getHeaderValue('message-id');
510 }
511 $msg = null;
512 if (isset($_POST['body']) && !is_utf8($_POST['body'])) {
513 $_POST['body'] = utf8_encode($_POST['body']);
514 }
515 if (empty($hdr_values['Subject'])) {
516 Banana::$page->trig(_b_('Le message doit avoir un sujet'));
517 } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment']) && $_FILES['attachment']['name']) {
518 $uploaded =& $_FILES['attachment'];
519 if (!is_uploaded_file($uploaded['tmp_name'])) {
520 Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier'));
521 } else {
522 $msg = BananaMessage::newMessage($hdr_values, $_POST['body'], $uploaded);
523 }
524 } else {
525 $msg = BananaMessage::newMessage($hdr_values, $_POST['body']);
526 }
527 if (!is_null($msg)) {
528 if (Banana::$protocole->send($msg)) {
529 $this->loadSpool($group);
530 $newid = Banana::$spool->updateUnread(Banana::$profile['lastnews']);
531 Banana::$page->redirect(array('group' => $group, 'artid' => $newid ? $newid : $artid));
532 } else {
533 Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
534 . Banana::$protocole->lastError());
535 }
536 }
537 } else {
538 if (!is_null($artid)) {
539 $msg =& $this->loadMessage($group, $artid);
540 $body = $msg->getSender() . _b_(' a écrit :') . "\n" . $msg->quote();
541 $subject = $msg->getHeaderValue('subject');
542 $headers['Subject']['user'] = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $subject);
543 $target = $msg->getHeaderValue($hdrs['reply']);
544 if (empty($target)) {
545 $target = $group;
546 }
547 $headers[$hdrs['dest']]['user'] =& $target;
548 } else {
549 $body = '';
550 $headers[$hdrs['dest']]['user'] = $group;
551 }
552 if (Banana::$profile['signature']) {
553 $body .= "\n\n-- \n" . Banana::$profile['signature'];
554 }
555 Banana::$page->assign('body', $body);
556 }
557
558 Banana::$page->assign('maxfilesize', Banana::$msgedit_maxfilesize);
559 Banana::$page->assign('can_attach', Banana::$msgedit_canattach);
560 Banana::$page->assign('headers', $headers);
561 return true;
562 }
563
564 protected function action_cancelMessage($group, $artid)
565 {
566 Banana::$page->setPage('cancel');
567 $msg =& $this->loadMessage($group, $artid);
568 if (!$msg->canCancel()) {
569 return _b_('Vous n\'avez pas les droits suffisants pour supprimer ce message');
570 }
571 if (isset($_POST['cancel'])) {
572 $this->loadSpool($group);
573 $ndx = Banana::$spool->getNdX($id) - 1;
574 if (!Banana::$protocole->cancel($msg)) {
575 return _b_('Une erreur s\'est produite lors de l\'annulation du message :') . '<br />'
576 . Banana::$protocole->lastError();
577 }
578 if ($ndx < 50) {
579 $ndx = 0;
580 }
581 $this->removeMessage($group, $artid);
582 Banana::$page->redirect(Array('group' => $group, 'first' => $ndx));
583 }
584
585 Banana::$page->assign_by_ref('message', $msg);
586 Banana::$page->assign('body', $msg->getFormattedBody());
587 Banana::$page->assign('headers', Banana::$msgshow_headers);
588 return true;
589 }
590
591 /**************************************************************************/
592 /* Spoolgen functions */
593 /**************************************************************************/
594
595 private function checkErrors()
596 {
597 if (Banana::$protocole->lastErrno()) {
598 echo "\nL'erreur suivante s'est produite : "
599 . Banana::$protocole->lastErrno() . " "
600 . Banana::$protocole->lastError() . "\n";
601 return false;
602 }
603 return true;
604 }
605
606 static public function createAllSpool(array $protos)
607 {
608 foreach ($protos as $proto) {
609 $banana = new Banana(array(), $proto);
610
611 if (!$banana->checkErrors()) {
612 continue;
613 }
614 $groups = Banana::$protocole->getBoxList();
615 if (!$banana->checkErrors()) {
616 continue;
617 }
618
619 print "** $proto **\n";
620 foreach (array_keys($groups) as $g) {
621 print "Generating spool for $g: ";
622 Banana::$group = $g;
623 $spool = $banana->loadSpool($g);
624 if (!$banana->checkErrors()) {
625 break;
626 }
627 print "done.\n";
628 unset($spool);
629 Banana::$spool = null;
630 }
631 print "\n";
632 }
633 }
634
635 static public function refreshAllFeeds(array $protos)
636 {
637 Banana::load('feed');
638 Banana::$feed_updateOnDemand = true; // In order to force update
639 foreach ($protos as $proto) {
640 $banana = new Banana(array(), $proto);
641
642 if (!$banana->checkErrors()) {
643 continue;
644 }
645 $groups = Banana::$protocole->getBoxList();
646 if (!$banana->checkErrors()) {
647 continue;
648 }
649
650 print "** $proto **\n";
651 foreach (array_keys($groups) as $g) {
652 print "Generating feed cache for $g: ";
653 Banana::$group = $g;
654 $spool = $banana->loadSpool($g);
655 if (!$banana->checkErrors()) {
656 break;
657 }
658 $feed =& BananaFeed::getFeed();
659 print "done.\n";
660 unset($feed);
661 unset($spool);
662 Banana::$spool = null;
663 }
664 print "\n";
665 }
666 }
667
668 /**************************************************************************/
669 /* Private functions */
670 /**************************************************************************/
671
672 protected function loadSpool($group)
673 {
674 Banana::load('spool');
675 if (!Banana::$spool || Banana::$spool->group != $group) {
676 $clean = false;
677 if (php_sapi_name() != 'cli') {
678 if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
679 Banana::$spool = unserialize($_SESSION['banana_spool']);
680 $clean = @(Banana::$profile['lastnews'] != $_SESSION['banana_lastnews']);
681 } else {
682 unset($_SESSION['banana_message']);
683 unset($_SESSION['banana_artid']);
684 unset($_SESSION['banana_showhdr']);
685 }
686 }
687 BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup'] || $clean);
688 if (php_sapi_name() != 'cli') {
689 $_SESSION['banana_group'] = $group;
690 if (!Banana::$profile['display']) {
691 $_SESSION['banana_spool'] = serialize(Banana::$spool);
692 $_SESSION['banana_lastnews'] = Banana::$profile['lastnews'];
693 }
694 }
695 Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
696 }
697 return true;
698 }
699
700 protected function &loadMessage($group, $artid)
701 {
702 Banana::load('message');
703 if ($group == @$_SESSION['banana_group'] && $artid == @$_SESSION['banana_artid']
704 && isset($_SESSION['banana_message'])) {
705 $message = unserialize($_SESSION['banana_message']);
706 Banana::$msgshow_headers = $_SESSION['banana_showhdr'];
707 } else {
708 $message = Banana::$protocole->getMessage($artid);
709 $_SESSION['banana_group'] = $group;
710 $_SESSION['banana_artid'] = $artid;
711 $_SESSION['banana_message'] = serialize($message);
712 $_SESSION['banana_showhdr'] = Banana::$msgshow_headers;
713 }
714 Banana::$message =& $message;
715 return $message;
716 }
717
718 protected function removeMessage($group, $artid)
719 {
720 Banana::$spool->delId($artid);
721 if ($group == $_SESSION['banana_group']) {
722 if (!Banana::$profile['display']) {
723 $_SESSION['banana_spool'] = serialize(Banana::$spool);
724 }
725 if ($artid == $_SESSION['banana_artid']) {
726 unset($_SESSION['banana_message']);
727 unset($_SESSION['banana_showhdr']);
728 unset($_SESSION['banana_artid']);
729 }
730 }
731 $this->loadSpool($group);
732 return true;
733 }
734
735 static private function load($file)
736 {
737 $file = strtolower($file) . '.inc.php';
738 if (!@include_once dirname(__FILE__) . "/$file") {
739 require_once $file;
740 }
741 }
742 }
743
744 // vim:set et sw=4 sts=4 ts=4 enc=utf-8:
745 ?>