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