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