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