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