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