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