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