Add a 'markAsRead' hook.
[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 }
05114a3e
FB
483 if (function_exists('hook_markAsRead')) {
484 hook_markAsRead($group, $artid, $msg);
485 }
c4f176d8 486 Banana::$page->assign_by_ref('message', $msg);
487 Banana::$page->assign('extimages', Banana::$msgshow_hasextimages);
488 Banana::$page->assign('headers', Banana::$msgshow_headers);
489 Banana::$page->assign('type', $partid);
490 return true;
491 }
492
493 protected function action_newMessage($group, $artid)
494 {
495 Banana::$page->setPage('new');
496 if (!Banana::$protocole->canSend()) {
497 return _b_('Vous n\'avez pas le droit de poster');
498 }
499 $hdrs = Banana::$protocole->requestedHeaders();
500 $headers = array();
501 foreach ($hdrs as $header) {
502 $headers[$header] = array('name' => BananaMessage::translateHeaderName($header));
503 if (isset(Banana::$profile['headers'][$header])) {
504 $headers[$header]['fixed'] = Banana::$profile['headers'][$header];
505 }
506 }
507 if (isset($_POST['sendmessage'])) {
508 $hdr_values = array();
509 foreach ($hdrs as $header) {
510 $hdr_values[$header] = isset($headers[$header]['fixed']) ? $headers[$header]['fixed'] : @$_POST[$header];
2ef5a22c 511 if (!is_utf8($hdr_values[$header])) {
512 $hdr_values[$header] = utf8_encode($hdr_values[$header]);
513 }
c4f176d8 514 }
a48027e6 515 $values = preg_split('/[,; ]/', $hdr_values[$hdrs['dest']]);
56b35f9c 516 $hdr_values[$hdrs['dest']] = preg_replace('/,+/', ',', implode(',', $values));
ee472ac6 517 if (!is_null($artid)) {
c4f176d8 518 $old =& $this->loadMessage($group, $artid);
3172a611 519 $hdr_values['References'] = $old->getHeaderValue('references') . ' ' . $old->getHeaderValue('message-id');
c4f176d8 520 }
521 $msg = null;
2ef5a22c 522 if (isset($_POST['body']) && !is_utf8($_POST['body'])) {
523 $_POST['body'] = utf8_encode($_POST['body']);
524 }
c4f176d8 525 if (empty($hdr_values['Subject'])) {
526 Banana::$page->trig(_b_('Le message doit avoir un sujet'));
b2b4d613 527 } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment']) && $_FILES['attachment']['name']) {
528 $uploaded =& $_FILES['attachment'];
c4f176d8 529 if (!is_uploaded_file($uploaded['tmp_name'])) {
530 Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier'));
531 } else {
532 $msg = BananaMessage::newMessage($hdr_values, $_POST['body'], $uploaded);
533 }
534 } else {
535 $msg = BananaMessage::newMessage($hdr_values, $_POST['body']);
536 }
537 if (!is_null($msg)) {
538 if (Banana::$protocole->send($msg)) {
a7081406 539 $this->loadSpool($group);
bffb37b4 540 $newid = Banana::$spool->updateUnread(Banana::$profile['lastnews']);
541 Banana::$page->redirect(array('group' => $group, 'artid' => $newid ? $newid : $artid));
b2b4d613 542 } else {
543 Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
c4f176d8 544 . Banana::$protocole->lastError());
56b35f9c 545 $body = $_POST['body'];
b2b4d613 546 }
c4f176d8 547 }
548 } else {
549 if (!is_null($artid)) {
550 $msg =& $this->loadMessage($group, $artid);
551 $body = $msg->getSender() . _b_(' a écrit :') . "\n" . $msg->quote();
552 $subject = $msg->getHeaderValue('subject');
553 $headers['Subject']['user'] = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $subject);
554 $target = $msg->getHeaderValue($hdrs['reply']);
555 if (empty($target)) {
556 $target = $group;
557 }
558 $headers[$hdrs['dest']]['user'] =& $target;
559 } else {
560 $body = '';
561 $headers[$hdrs['dest']]['user'] = $group;
562 }
563 if (Banana::$profile['signature']) {
564 $body .= "\n\n-- \n" . Banana::$profile['signature'];
565 }
c4f176d8 566 }
56b35f9c 567 Banana::$page->assign('body', $body);
c4f176d8 568
569 Banana::$page->assign('maxfilesize', Banana::$msgedit_maxfilesize);
570 Banana::$page->assign('can_attach', Banana::$msgedit_canattach);
571 Banana::$page->assign('headers', $headers);
572 return true;
573 }
574
575 protected function action_cancelMessage($group, $artid)
576 {
577 Banana::$page->setPage('cancel');
578 $msg =& $this->loadMessage($group, $artid);
579 if (!$msg->canCancel()) {
580 return _b_('Vous n\'avez pas les droits suffisants pour supprimer ce message');
581 }
582 if (isset($_POST['cancel'])) {
583 $this->loadSpool($group);
c4f176d8 584 if (!Banana::$protocole->cancel($msg)) {
585 return _b_('Une erreur s\'est produite lors de l\'annulation du message :') . '<br />'
586 . Banana::$protocole->lastError();
587 }
c4f176d8 588 $this->removeMessage($group, $artid);
d35878e0 589 Banana::$page->redirect(Array('group' => $group));
c4f176d8 590 }
591
592 Banana::$page->assign_by_ref('message', $msg);
593 Banana::$page->assign('body', $msg->getFormattedBody());
594 Banana::$page->assign('headers', Banana::$msgshow_headers);
595 return true;
596 }
597
598 /**************************************************************************/
599 /* Spoolgen functions */
600 /**************************************************************************/
601
602 private function checkErrors()
603 {
604 if (Banana::$protocole->lastErrno()) {
605 echo "\nL'erreur suivante s'est produite : "
606 . Banana::$protocole->lastErrno() . " "
607 . Banana::$protocole->lastError() . "\n";
608 return false;
609 }
610 return true;
e02edbfe 611 }
c4f176d8 612
613 static public function createAllSpool(array $protos)
614 {
615 foreach ($protos as $proto) {
616 $banana = new Banana(array(), $proto);
617
618 if (!$banana->checkErrors()) {
619 continue;
620 }
621 $groups = Banana::$protocole->getBoxList();
622 if (!$banana->checkErrors()) {
623 continue;
624 }
625
626 print "** $proto **\n";
627 foreach (array_keys($groups) as $g) {
e02edbfe 628 print "Generating spool for $g: ";
c4f176d8 629 Banana::$group = $g;
630 $spool = $banana->loadSpool($g);
631 if (!$banana->checkErrors()) {
632 break;
633 }
634 print "done.\n";
635 unset($spool);
e02edbfe 636 Banana::$spool = null;
c4f176d8 637 }
638 print "\n";
639 }
640 }
641
e02edbfe 642 static public function refreshAllFeeds(array $protos)
643 {
644 Banana::load('feed');
645 Banana::$feed_updateOnDemand = true; // In order to force update
646 foreach ($protos as $proto) {
647 $banana = new Banana(array(), $proto);
648
649 if (!$banana->checkErrors()) {
650 continue;
651 }
652 $groups = Banana::$protocole->getBoxList();
653 if (!$banana->checkErrors()) {
654 continue;
655 }
656
657 print "** $proto **\n";
658 foreach (array_keys($groups) as $g) {
659 print "Generating feed cache for $g: ";
660 Banana::$group = $g;
661 $spool = $banana->loadSpool($g);
662 if (!$banana->checkErrors()) {
663 break;
664 }
665 $feed =& BananaFeed::getFeed();
666 print "done.\n";
667 unset($feed);
668 unset($spool);
669 Banana::$spool = null;
670 }
671 print "\n";
672 }
673 }
64f89fae 674
c4f176d8 675 /**************************************************************************/
676 /* Private functions */
677 /**************************************************************************/
678
679 protected function loadSpool($group)
680 {
681 Banana::load('spool');
682 if (!Banana::$spool || Banana::$spool->group != $group) {
0fa5e39a 683 BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup']);
c4f176d8 684 Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
685 }
686 return true;
687 }
688
689 protected function &loadMessage($group, $artid)
690 {
691 Banana::load('message');
692 if ($group == @$_SESSION['banana_group'] && $artid == @$_SESSION['banana_artid']
693 && isset($_SESSION['banana_message'])) {
4f18bf36 694 $message = unserialize($_SESSION['banana_message']);
c4f176d8 695 Banana::$msgshow_headers = $_SESSION['banana_showhdr'];
696 } else {
697 $message = Banana::$protocole->getMessage($artid);
698 $_SESSION['banana_group'] = $group;
699 $_SESSION['banana_artid'] = $artid;
4f18bf36 700 $_SESSION['banana_message'] = serialize($message);
c4f176d8 701 $_SESSION['banana_showhdr'] = Banana::$msgshow_headers;
702 }
703 Banana::$message =& $message;
704 return $message;
705 }
706
707 protected function removeMessage($group, $artid)
708 {
709 Banana::$spool->delId($artid);
710 if ($group == $_SESSION['banana_group']) {
711 if (!Banana::$profile['display']) {
4f18bf36 712 $_SESSION['banana_spool'] = serialize(Banana::$spool);
c4f176d8 713 }
714 if ($artid == $_SESSION['banana_artid']) {
715 unset($_SESSION['banana_message']);
716 unset($_SESSION['banana_showhdr']);
717 unset($_SESSION['banana_artid']);
718 }
719 }
720 $this->loadSpool($group);
721 return true;
722 }
723
568e98af 724 static public function load($file)
c4f176d8 725 {
726 $file = strtolower($file) . '.inc.php';
727 if (!@include_once dirname(__FILE__) . "/$file") {
728 require_once $file;
729 }
730 }
731}
732
733// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
734?>