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