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