78cd27b3 |
1 | <?php |
2 | /******************************************************************************** |
3 | * install.d/config.inc.php : configuration 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 | class Banana |
11 | { |
d28aa62d |
12 | var $maxspool = 3000; |
78cd27b3 |
13 | |
d28aa62d |
14 | var $hdecode = array('from','name','organization','subject'); |
28ab52c0 |
15 | var $parse_hdr = array('content-disposition', 'content-transfer-encoding', |
16 | 'content-type', 'content-id', 'date', 'followup-to', |
17 | 'from', 'message-id', 'newsgroups', 'organization', |
18 | 'references', 'subject', 'x-face'); |
19 | var $show_hdr = array('from', 'newsgroups', 'followup', 'date', |
20 | 'organization', 'references', 'x-face'); |
78cd27b3 |
21 | |
cc43419f |
22 | /** Favorites MIMEtypes to use, by order for reading multipart messages |
23 | */ |
24 | var $body_mime = array('text/plain', 'text/html', 'text/richtext'); |
a1937df3 |
25 | /** Indicate wether posting attachment is allowed |
26 | */ |
27 | var $can_attach = true; |
28 | /** Maximum allowed file size for attachment |
29 | */ |
ca3b1040 |
30 | var $maxfilesize = 100000; |
31 | /** Indicate wether x-face should be skinned as specials data or not |
32 | */ |
33 | var $formatxface = true; |
78cd27b3 |
34 | |
4f6a209a |
35 | /** Regexp for selecting newsgroups to show (if empty, match all newsgroups) |
36 | * ex : '^xorg\..*' for xorg.* |
37 | */ |
38 | var $grp_pattern; |
39 | |
d28aa62d |
40 | var $tbefore = 5; |
41 | var $tafter = 5; |
42 | var $tmax = 50; |
78cd27b3 |
43 | |
d28aa62d |
44 | var $wrap = 74; |
87514711 |
45 | /** Match an url |
46 | * Should be included in a regexp delimited using ! (eg: "!$url_regexp!i") |
47 | * If it matches, return 3 main parts : |
48 | * \\1 and \\3 are delimiters |
49 | * \\2 is the url |
50 | * |
51 | * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches); |
52 | * $matches[1] = "[" |
53 | * $matches[2] = "http://www.polytechnique.org" |
54 | * $matches[3] = "]" |
55 | */ |
6439e93c |
56 | var $url_regexp = '(["\[])?((?:https?|ftp|news)://(?:&|\.*,*[a-z@0-9~%$£µ&i#\-+=_/\?])*)(["\]])?'; |
78cd27b3 |
57 | |
87514711 |
58 | |
a1937df3 |
59 | /** Boundary for multipart messages |
60 | */ |
f12fdb59 |
61 | var $boundary = 'bananaBoundary42'; |
62 | /** Global headers to use for messages |
a1937df3 |
63 | */ |
f12fdb59 |
64 | var $custom = "Mime-Version: 1.0\nUser-Agent: Banana @VERSION@\n"; |
a1937df3 |
65 | /** Global headers to use from multipart messages |
66 | */ |
f12fdb59 |
67 | var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\n"; |
68 | /** Body type when using plain text |
a1937df3 |
69 | */ |
f12fdb59 |
70 | var $custom_plain= "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit\n"; |
78cd27b3 |
71 | |
a1937df3 |
72 | /** News serveur to use |
73 | */ |
d28aa62d |
74 | var $host = 'news://localhost:119/'; |
78cd27b3 |
75 | |
a1937df3 |
76 | /** User profile |
77 | */ |
d28aa62d |
78 | var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '', |
78cd27b3 |
79 | 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array()); |
80 | |
1254696c |
81 | var $state = Array('group' => null, 'artid' => null, 'action' => null); |
78cd27b3 |
82 | var $nntp; |
83 | var $groups; |
84 | var $newgroups; |
85 | var $post; |
86 | var $spool; |
87 | |
f6df9eb2 |
88 | var $get; |
1786dc36 |
89 | |
78cd27b3 |
90 | function Banana() |
91 | { |
92 | $this->_require('NetNNTP'); |
93 | setlocale(LC_ALL, $this->profile['locale']); |
94 | $this->nntp = new nntp($this->host); |
856dc84a |
95 | if (!$this->nntp || !$this->nntp->valid) { |
96 | $this->nntp = null; |
97 | } |
78cd27b3 |
98 | } |
99 | |
f6df9eb2 |
100 | /** Run Banana |
101 | * @param STRING class Name of the class to use |
102 | * @param ARRAY myget If defined is used instead of get |
103 | */ |
1786dc36 |
104 | function run($class = 'Banana', $myget = null) |
78cd27b3 |
105 | { |
106 | global $banana; |
aef14768 |
107 | |
78cd27b3 |
108 | Banana::_require('misc'); |
109 | $banana = new $class(); |
110 | |
1786dc36 |
111 | if (is_null($myget)) { |
112 | $banana->get = $_GET; |
113 | } else { |
114 | $banana->get = $myget; |
115 | } |
116 | |
78cd27b3 |
117 | if (!$banana->nntp) { |
ca52cc4c |
118 | $banana->state['page'] = 'error'; |
119 | return makeTable('<p class="error">'._b_('Impossible de contacter le serveur').'</p>'); |
78cd27b3 |
120 | } |
121 | |
f37bac43 |
122 | $group = empty($banana->get['group']) ? null : $banana->get['group']; |
b2f7dc0b |
123 | if (!is_null($group) |
124 | && isset($banana->grp_pattern) && !preg_match('/' . $banana->grp_pattern . '/', $group)) { |
ca52cc4c |
125 | $banana->state['page'] = 'error'; |
126 | return makeTable('<p class="error">' |
3c3d29bb |
127 | . $group . _b_(' : ce newsgroup n\'existe pas ou vous n\'avez pas l\'autorisation d\'y accéder') |
ca52cc4c |
128 | . '</p>'); |
3c3d29bb |
129 | } |
1786dc36 |
130 | $artid = empty($banana->get['artid']) ? null : strtolower($banana->get['artid']); |
131 | $partid = !isset($banana->get['part']) ? -1 : $banana->get['part']; |
1254696c |
132 | $action = !isset($banana->get['action']) ? null : $banana->get['action']; |
133 | $banana->state = Array ('group' => $group, 'artid' => $artid, 'action' => $action); |
78cd27b3 |
134 | |
135 | if (is_null($group)) { |
1786dc36 |
136 | if (isset($banana->get['subscribe'])) { |
ca52cc4c |
137 | $banana->state['page'] = 'subscribe'; |
92f5ea62 |
138 | return makeTable($banana->action_listSubs()); |
20e25a42 |
139 | } elseif (isset($_POST['validsubs'])) { |
78cd27b3 |
140 | $banana->action_saveSubs(); |
141 | } |
ca52cc4c |
142 | $banana->state['page'] = 'forums'; |
92f5ea62 |
143 | return makeTable($banana->action_listGroups()); |
78cd27b3 |
144 | |
145 | } elseif (is_null($artid)) { |
78cd27b3 |
146 | if (isset($_POST['action']) && $_POST['action'] == 'new') { |
92f5ea62 |
147 | return makeTable($banana->action_doFup($group, isset($_POST['artid']) ? intval($_POST['artid']) : -1)); |
1254696c |
148 | } elseif ($action == 'new') { |
ca52cc4c |
149 | $banana->state['page'] = 'action'; |
92f5ea62 |
150 | return makeTable($banana->action_newFup($group)); |
78cd27b3 |
151 | } else { |
ca52cc4c |
152 | $banana->state['page'] = 'group'; |
92f5ea62 |
153 | return makeTable($banana->action_showThread($group, isset($banana->get['first']) ? intval($banana->get['first']) : 1)); |
78cd27b3 |
154 | } |
155 | |
156 | } else { |
78cd27b3 |
157 | if (isset($_POST['action']) && $_POST['action']=='cancel') { |
158 | $res = $banana->action_cancelArticle($group, $artid); |
159 | } else { |
160 | $res = ''; |
161 | } |
162 | |
1254696c |
163 | if (!is_null($action)) { |
ca52cc4c |
164 | $banana->state['page'] = 'action'; |
1254696c |
165 | switch ($action) { |
78cd27b3 |
166 | case 'cancel': |
1f75b135 |
167 | $res .= $banana->action_showArticle($group, $artid, $partid); |
78cd27b3 |
168 | if ($banana->post->checkcancel()) { |
169 | $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>' |
5440bf74 |
170 | . '<form action="' |
f6df9eb2 |
171 | . htmlentities(makeLink(Array('group' => $group, |
172 | 'artid' => $artid))) |
173 | . '" method="post"><p>' |
78cd27b3 |
174 | . '<input type="hidden" name="action" value="cancel" />' |
175 | . '<input type="submit" value="Annuler !" />' |
176 | . '</p></form>'; |
92f5ea62 |
177 | return makeTable($form . $res); |
78cd27b3 |
178 | } |
92f5ea62 |
179 | return makeTable("" . $res); |
78cd27b3 |
180 | |
181 | case 'new': |
92f5ea62 |
182 | return makeTable($banana->action_newFup($group, $artid)); |
78cd27b3 |
183 | } |
184 | } |
7a0e2710 |
185 | |
1786dc36 |
186 | if (isset($banana->get['pj'])) { |
1254696c |
187 | $view = false; |
188 | if ($action == 'view') { |
189 | $view = true; |
7a0e2710 |
190 | } |
1254696c |
191 | $att = $banana->action_getAttachment($group, $artid, $banana->get['pj'], $view); |
92f5ea62 |
192 | return makeTable($res . $att); |
7a0e2710 |
193 | } |
194 | |
ca52cc4c |
195 | $banana->state['page'] = 'message'; |
92f5ea62 |
196 | return makeTable($banana->action_showArticle($group, $artid, $partid)); |
78cd27b3 |
197 | } |
198 | } |
199 | |
200 | /**************************************************************************/ |
201 | /* actions */ |
202 | /**************************************************************************/ |
203 | |
204 | function action_saveSubs() |
205 | { |
206 | return; |
207 | } |
208 | |
209 | function action_listGroups() |
210 | { |
211 | $this->_newGroup(); |
212 | |
92f5ea62 |
213 | $res = $this->groups->to_html(); |
78cd27b3 |
214 | if (count($this->newgroups->overview)) { |
215 | $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>'; |
216 | $res .= $this->newgroups->to_html(); |
217 | } |
218 | |
219 | $this->nntp->quit(); |
92f5ea62 |
220 | return $res; |
78cd27b3 |
221 | } |
222 | |
223 | function action_listSubs() |
224 | { |
225 | $this->_require('groups'); |
226 | $this->groups = new BananaGroups(BANANA_GROUP_ALL); |
227 | |
92f5ea62 |
228 | $res = $this->groups->to_html(true); |
78cd27b3 |
229 | |
230 | $this->nntp->quit(); |
231 | return $res; |
232 | } |
233 | |
234 | function action_showThread($group, $first) |
235 | { |
856dc84a |
236 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
f37bac43 |
237 | return '<p class="error">'._b_('Impossible charger la liste des messages de ') . $group . '</p>'; |
856dc84a |
238 | } |
78cd27b3 |
239 | |
240 | if ($first > count($this->spool->overview)) { |
241 | $first = count($this->spool->overview); |
242 | } |
243 | |
244 | $first = $first - ($first % $this->tmax) + 1; |
78cd27b3 |
245 | |
92f5ea62 |
246 | $pages = displayPages($first); |
247 | $res = $pages . $this->spool->to_html($first, $first+$this->tmax) . $pages; |
78cd27b3 |
248 | |
249 | $this->nntp->quit(); |
250 | |
92f5ea62 |
251 | return $res; |
78cd27b3 |
252 | } |
253 | |
1f75b135 |
254 | function action_showArticle($group, $id, $part) |
78cd27b3 |
255 | { |
856dc84a |
256 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
f37bac43 |
257 | return '<p class="error">'._b_('Impossible charger la liste des messages de ') . $group . '</p>'; |
856dc84a |
258 | } |
259 | |
260 | if (!$this->_newPost($id)) { |
78cd27b3 |
261 | if ($this->nntp->lasterrorcode == "423") { |
262 | $this->spool->delid($id); |
263 | } |
264 | $this->nntp->quit(); |
92f5ea62 |
265 | return '<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>'; |
78cd27b3 |
266 | } |
267 | |
92f5ea62 |
268 | $res = $this->post->to_html($part); |
78cd27b3 |
269 | |
270 | $this->nntp->quit(); |
271 | |
92f5ea62 |
272 | return $res; |
78cd27b3 |
273 | } |
274 | |
7a0e2710 |
275 | function action_getAttachment($group, $id, $pjid, $action) |
276 | { |
856dc84a |
277 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
278 | return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>'; |
279 | } |
280 | |
281 | if (!$this->_newPost($id)) { |
7a0e2710 |
282 | if ($this->nntp->lasterrorcode == "423") { |
283 | $this->spool->delid($id); |
284 | } |
285 | $this->nntp->quit(); |
92f5ea62 |
286 | return '<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>'; |
7a0e2710 |
287 | } |
288 | |
289 | $this->nntp->quit(); |
290 | if ($this->post->get_attachment($pjid, $action)) { |
291 | return ""; |
292 | } else { |
92f5ea62 |
293 | return '<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>'; |
7a0e2710 |
294 | } |
295 | } |
296 | |
78cd27b3 |
297 | function action_cancelArticle($group, $id) |
298 | { |
856dc84a |
299 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
300 | return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>'; |
301 | } |
302 | |
303 | if (!$this->_newPost($id)) { |
304 | return '<p class="error">'._b_('Impossible de trouver le message à annuler').'</p>'; |
305 | } |
78cd27b3 |
306 | $mid = array_search($id, $this->spool->ids); |
307 | |
308 | if (!$this->post->checkcancel()) { |
309 | return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>'; |
310 | } |
311 | $msg = 'From: '.$this->profile['name']."\n" |
312 | . "Newsgroups: $group\n" |
313 | . "Subject: cmsg $mid\n" |
314 | . $this->custom |
315 | . "Control: cancel $mid\n" |
316 | . "\n" |
317 | . "Message canceled with Banana"; |
318 | if ($this->nntp->post($msg)) { |
6951df36 |
319 | $ndx = $this->spool->getndx($artid) - 1; |
320 | if ($ndx > 50) { |
321 | $ndx = 0; |
322 | } |
78cd27b3 |
323 | $this->spool->delid($id); |
324 | $this->nntp->quit(); |
41b90d00 |
325 | redirectInBanana(Array('group' => $group, |
6951df36 |
326 | 'first' => $ndx)); |
78cd27b3 |
327 | } else { |
328 | return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>'; |
329 | } |
330 | } |
331 | |
332 | function action_newFup($group, $id = -1) |
333 | { |
334 | $subject = $body = ''; |
335 | $target = $group; |
336 | |
80110636 |
337 | if (@$_POST['action'] == 'new') { |
338 | $subject = $_POST['subject']; |
339 | $body = $_POST['body']; |
340 | $target = $_POST['newsgroups']; |
341 | $followup = $_POST['followup']; |
52cafcf1 |
342 | $this->state['page'] = 'action'; |
343 | $this->state['group'] = $group; |
344 | $this->state['action'] = 'new'; |
345 | if ($id != -1) { |
346 | $this->state['artid'] = $id; |
347 | } |
80110636 |
348 | } elseif ($id > 0) { |
78cd27b3 |
349 | $this->nntp->group($group); |
856dc84a |
350 | if ($this->_newPost($id)) { |
52cafcf1 |
351 | $subject = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $this->post->headers['subject']); |
2c839685 |
352 | $body = to_entities(utf8_encode($this->post->name." "._b_("a écrit"))." :\n" |
80110636 |
353 | . wrap($this->post->get_body(), "> ") |
2c839685 |
354 | . ($this->profile['sig'] ? "\n\n-- \n". $this->profile['sig'] : '')); |
80110636 |
355 | $target = isset($this->post->headers['followup-to']) ? |
356 | $this->post->headers['followup-to'] : $this->post->headers['newsgroups']; |
357 | $followup = null; |
78cd27b3 |
358 | } |
a8637973 |
359 | } else { |
2c839685 |
360 | $targe = $group; |
361 | $subject = $followup = null; |
362 | $body = $this->profile['sig'] ? "\n\n-- \n". $this->profile['sig'] : ''; |
78cd27b3 |
363 | } |
364 | |
365 | $this->nntp->quit(); |
366 | |
92f5ea62 |
367 | $html = '<form enctype="multipart/form-data" action="' |
f6df9eb2 |
368 | . htmlentities(makeLink(Array('group' => $group))) |
80110636 |
369 | . '" method="post" accept-charset="utf-8">' |
370 | . '<table class="bicol" cellpadding="0" cellspacing="0">' |
371 | . '<tr><th colspan="2">' . _b_('En-têtes') . '</th></tr>' |
372 | . '<tr><td>' . _b_('Nom') . '</td>' |
373 | . '<td>' . htmlentities($this->profile['name']) . '</td></tr>' |
374 | . '<tr><td>' . _b_('Sujet') . '</td>' |
375 | . '<td><input type="text" name="subject" value="' . htmlentities($subject) . '" size="60" /></td></tr>' |
376 | . '<tr><td>' . _b_('Forums') . '</td>' |
377 | . '<td><input type="text" name="newsgroups" value="' . htmlentities($target) . '" size="60" /></td></tr>' |
378 | . '<tr><td>' . _b_('Suivi à') . '</td>' |
379 | . '<td><input type="text" name="followup" value="' . htmlentities($followup). '" size="60" /></td></tr>' |
380 | . '<tr><td>' . _b_('Organisation') . '</td>' |
381 | . '<td>' . $this->profile['org'] . '</td></tr>' |
382 | . '<tr><th colspan="2">' . _b_('Corps') . '</th></tr>' |
383 | . '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">' |
a8637973 |
384 | . $body . '</textarea></td></tr>'; |
e9e9463c |
385 | if ($this->can_attach) { |
80110636 |
386 | $html .= '<tr><th colspan="2">' . _b_('Pièce jointe') . '</th></tr>' |
387 | . '<tr><td colspan="2">' |
388 | . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $this->maxfilesize . '" />' |
389 | . '<input type="file" name="newpj" size="40"/></td></tr>'; |
e9e9463c |
390 | } |
f6df9eb2 |
391 | $html .= '<tr><th colspan="2">'; |
52cafcf1 |
392 | if ($id != -1) { |
393 | $html .= '<input type="hidden" name="artid" value="' . $id . '" />'; |
78cd27b3 |
394 | } |
80110636 |
395 | $html .= '<input type="hidden" name="action" value="new" />' |
396 | . '<input type="submit" value="' . _b_('Envoyer le message') . '" /></th></tr>' |
397 | . '</table></form>'; |
78cd27b3 |
398 | |
92f5ea62 |
399 | return $html; |
78cd27b3 |
400 | } |
401 | |
402 | function action_doFup($group, $artid = -1) |
403 | { |
80110636 |
404 | if ( ! (is_utf8($_POST['subject']) && is_utf8($_POST['body']))) { |
405 | foreach(Array('subject', 'body') as $key) { |
78cd27b3 |
406 | $_POST[$key] = utf8_encode($_POST[$key]); |
407 | } |
408 | } |
fb6bea16 |
409 | |
f6df9eb2 |
410 | $forums = preg_split('/\s*(,|;)\s*/', $_POST['newsgroups']); |
411 | $fup = $_POST['followup']; |
412 | if (sizeof($forums) > 1) { |
413 | if (empty($fup)) { |
414 | $fup = $forums[0]; |
415 | } |
416 | } |
417 | $to = implode(',', $forums); |
418 | |
856dc84a |
419 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
420 | return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>'; |
421 | } |
f6df9eb2 |
422 | |
78cd27b3 |
423 | $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']); |
d14182c8 |
424 | $msg = 'From: ' . $this->profile['name'] . "\n" |
fb6bea16 |
425 | . "Newsgroups: ". $to . "\n" |
d14182c8 |
426 | . "Subject: " . headerEncode($_POST['subject'], 128) . "\n" |
78cd27b3 |
427 | . (empty($this->profile['org']) ? '' : "Organization: {$this->profile['org']}\n") |
d14182c8 |
428 | . (empty($fup) ? '' : 'Followup-To: ' . $fup . "\n"); |
78cd27b3 |
429 | |
430 | if ($artid != -1) { |
431 | $this->_require('post'); |
432 | $post = new BananaPost($artid); |
856dc84a |
433 | if (!$post || !$post->valid) { |
434 | return '<p class="error">'._b_('Impossible charger le message d\'origine').'</p>'; |
435 | } |
78cd27b3 |
436 | $refs = ( isset($post->headers['references']) ? $post->headers['references']." " : "" ); |
437 | $msg .= "References: $refs{$post->headers['message-id']}\n"; |
438 | } |
439 | |
f12fdb59 |
440 | $body_headers = $this->custom_plain; |
d6f4a433 |
441 | $body = wrap($body, ""); |
0a61409e |
442 | |
443 | // include attachment in the body |
d28aa62d |
444 | $uploaded = $this->_upload('newpj'); |
ef84d640 |
445 | switch ($uploaded['error']) { |
446 | case UPLOAD_ERR_OK: |
f12fdb59 |
447 | $this->custom = $this->custom_mp.$this->custom; |
448 | $body = $this->_make_part($body_headers, $body); |
449 | $file_head = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n" |
450 | . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n" |
451 | . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n"; |
452 | $body .= $this->_make_part($file_head, $uploaded['data']); |
453 | $body .= "\n--".$this->boundary.'--'; |
ef84d640 |
454 | break; |
455 | |
456 | case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: |
457 | return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ') |
458 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
459 | |
460 | case UPLOAD_ERR_PARTIAL: |
461 | return '<p class="error">'._b_('Erreur lors de l\'upload de ') |
462 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
463 | |
464 | case UPLOAD_ERR_NO_FILE: |
465 | return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ') |
466 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
467 | |
468 | case UPLOAD_ERR_NO_TMP_DIR: |
469 | return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ') |
470 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
f12fdb59 |
471 | |
472 | default: |
473 | $this->custom = $body_headers.$this->custom; |
d28aa62d |
474 | } |
0a61409e |
475 | |
476 | // finalise and post the message |
477 | $msg .= $this->custom.$this->profile['customhdr']."\n".$body; |
78cd27b3 |
478 | |
479 | if ($this->nntp->post($msg)) { |
f6df9eb2 |
480 | $dir = Array('group' => $group); |
481 | if ($artid != -1) { |
21b13732 |
482 | $dir['artid'] = $artid; |
f6df9eb2 |
483 | } |
41b90d00 |
484 | redirectInBanana($dir); |
78cd27b3 |
485 | } else { |
a8637973 |
486 | return '<p class="error">' . _b_('Impossible de poster le message. Le serveur a retourné l\'erreur :') . '</p>' |
487 | . '<pre class="error">' . utf8_encode($this->nntp->lasterrortext) .'</pre>' |
80110636 |
488 | . $this->action_newFup($group, $artid); |
78cd27b3 |
489 | } |
490 | } |
491 | |
492 | /**************************************************************************/ |
493 | /* Private functions */ |
494 | /**************************************************************************/ |
495 | |
496 | function _newSpool($group, $disp=0, $since='') { |
497 | $this->_require('spool'); |
498 | if (!$this->spool || $this->spool->group != $group) { |
499 | $this->spool = new BananaSpool($group, $disp, $since); |
856dc84a |
500 | if (!$this->spool || !$this->spool->valid) { |
501 | $this->spool = null; |
502 | return false; |
503 | } |
78cd27b3 |
504 | } |
e230b41a |
505 | if (count($this->profile['subscribe']) > 0) { |
506 | $this->_newGroup(false); |
507 | } |
856dc84a |
508 | return true; |
78cd27b3 |
509 | } |
510 | |
511 | function _newPost($id) |
512 | { |
513 | $this->_require('post'); |
514 | $this->post = new BananaPost($id); |
856dc84a |
515 | if (!$this->post || !$this->post->valid) { |
516 | $this->post = null; |
517 | return false; |
518 | } |
519 | return true; |
78cd27b3 |
520 | } |
521 | |
e230b41a |
522 | function _newGroup($showNew = true) |
78cd27b3 |
523 | { |
524 | $this->_require('groups'); |
525 | $this->groups = new BananaGroups(BANANA_GROUP_SUB); |
e230b41a |
526 | if ($showNew && $this->groups->type == BANANA_GROUP_SUB) { |
78cd27b3 |
527 | $this->newgroups = new BananaGroups(BANANA_GROUP_NEW); |
528 | } |
529 | } |
530 | |
531 | function _require($file) |
532 | { |
533 | require_once (dirname(__FILE__).'/'.$file.'.inc.php'); |
534 | } |
d28aa62d |
535 | |
536 | function _upload($file) |
537 | { |
538 | if ($_FILES[$file]['name'] == "") { |
539 | return Array( 'error' => -1 ); |
540 | } |
541 | |
542 | // upload |
543 | $_FILES[$file]['tmp_name']; |
544 | |
545 | // test if upload is ok |
546 | $file = $_FILES[$file]; |
547 | if ($file['size'] == 0 || $file['error'] != 0) { |
548 | if ($file['error'] == 0) { |
549 | $file['error'] = -1; |
550 | } |
551 | return $file; |
552 | } |
553 | |
554 | // adding custum data |
555 | $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :( |
556 | $encod = 'base64'; |
557 | if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) { |
558 | $mime = $format[1]; |
559 | $encod = $format[2]; |
560 | } |
561 | $data = fread(fopen($file['tmp_name'], 'r'), $file['size']); |
562 | if ($encod == 'base64') { |
563 | $data = chunk_split(base64_encode($data)); |
564 | } |
565 | $file['name'] = basename($file['name']); |
566 | $file['type'] = $mime; |
567 | $file['encoding'] = $encod; |
568 | $file['data'] = $data; |
569 | |
570 | return $file; |
571 | } |
f12fdb59 |
572 | |
573 | function _make_part($headers, $body) |
574 | { |
575 | return "\n--".$this->boundary."\n".$headers."\n".$body; |
576 | } |
78cd27b3 |
577 | } |
578 | |
f6df9eb2 |
579 | // vim:set et sw=4 sts=4 ts=4 |
78cd27b3 |
580 | ?> |