546f245f898de0455bdb16cc81d1709c98c6db40
2 /********************************************************************************
3 * install.d/config.inc.php : configuration file
4 * --------------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
14 var $hdecode = array('from','name','organization','subject');
15 var $parse_hdr = array('content-disposition', 'content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
16 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
17 var $show_hdr = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
19 /** Favorites MIMEtypes to use, by order for reading multipart messages
21 var $body_mime = array('text/plain', 'text/html', 'text/richtext');
22 /** Indicate wether posting attachment is allowed
24 var $can_attach = true
;
25 /** Maximum allowed file size for attachment
27 var $maxfilesize = 100000;
29 /** Regexp for selecting newsgroups to show (if empty, match all newsgroups)
30 * ex : '^xorg\..*' for xorg.*
40 * Should be included in a regexp delimited using ! (eg: "!$url_regexp!i")
41 * If it matches, return 3 main parts :
42 * \\1 and \\3 are delimiters
45 * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches);
47 * $matches[2] = "http://www.polytechnique.org"
50 var $url_regexp = '(["\[])?((?:https?|ftp|news)://(?:&|[a-z@0-9.~%$£µ&i#\-+=_/\?])*)(["\]])?';
53 /** Boundary for multipart messages
55 var $boundary = 'bananaBoundary42';
56 /** Global headers to use for messages
58 var $custom = "Mime-Version: 1.0\nUser-Agent: Banana @VERSION@\n";
59 /** Global headers to use from multipart messages
61 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\n";
62 /** Body type when using plain text
64 var $custom_plain= "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit\n";
66 /** News serveur to use
68 var $host = 'news://localhost:119/';
72 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
73 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
75 var $state = Array('group' => null
, 'artid' => null
);
84 $this->_require('NetNNTP');
85 setlocale(LC_ALL
, $this->profile
['locale']);
86 $this->nntp
= new nntp($this->host
);
89 function run($class = 'Banana')
93 Banana
::_require('misc');
94 $banana = new $class();
97 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
100 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
101 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
102 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
103 $banana->state
= Array ('group' => $group, 'artid' => $artid);
105 if (is_null($group)) {
107 if (isset($_GET['subscribe'])) {
108 return $banana->action_listSubs();
109 } elseif (isset($_POST['subscribe'])) {
110 $banana->action_saveSubs();
112 return $banana->action_listGroups();
114 } elseif (is_null($artid)) {
115 if (isset($_POST['action']) && $_POST['action'] == 'new') {
116 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
117 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
118 return $banana->action_newFup($group);
120 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
125 if (isset($_POST['action']) && $_POST['action']=='cancel') {
126 $res = $banana->action_cancelArticle($group, $artid);
131 if (isset($_GET['action'])) {
132 switch ($_GET['action']) {
134 $res .= $banana->action_showArticle($group, $artid, $partid);
135 if ($banana->post
->checkcancel()) {
136 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
137 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
138 . '<input type="hidden" name="action" value="cancel" />'
139 . '<input type="submit" value="Annuler !" />'
146 return $banana->action_newFup($group, $artid);
150 if (isset($_GET['pj'])) {
152 if (isset($_GET['action']) && $_GET['action'] == 'view') {
155 $att = $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
162 return $res . $banana->action_showArticle($group, $artid, $partid);
166 /**************************************************************************/
168 /**************************************************************************/
170 function action_saveSubs()
175 function action_listGroups()
179 $cuts = displayshortcuts();
180 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
181 if (count($this->newgroups
->overview
)) {
182 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
183 $res .= $this->newgroups
->to_html();
190 function action_listSubs()
192 $this->_require('groups');
193 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
195 $cuts = displayshortcuts();
196 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
202 function action_showThread($group, $first)
204 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
206 if ($first > count($this->spool
->overview
)) {
207 $first = count($this->spool
->overview
);
210 $first = $first - ($first %
$this->tmax
) +
1;
212 $cuts = displayshortcuts($first);
214 $res = '<h1>'.$group.'</h1>'.$cuts;
215 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
222 function action_showArticle($group, $id, $part)
224 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
225 $this->_newPost($id);
227 if ($this->nntp
->lasterrorcode
== "423") {
228 $this->spool
->delid($id);
231 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
234 $cuts = displayshortcuts();
235 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
236 $res .= $this->post
->to_html($part);
243 function action_getAttachment($group, $id, $pjid, $action)
245 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
246 $this->_newPost($id);
248 if ($this->nntp
->lasterrorcode
== "423") {
249 $this->spool
->delid($id);
252 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
256 if ($this->post
->get_attachment($pjid, $action)) {
259 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
263 function action_cancelArticle($group, $id)
265 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
266 $this->_newPost($id);
267 $mid = array_search($id, $this->spool
->ids
);
269 if (!$this->post
->checkcancel()) {
270 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
272 $msg = 'From: '.$this->profile
['name']."\n"
273 . "Newsgroups: $group\n"
274 . "Subject: cmsg $mid\n"
276 . "Control: cancel $mid\n"
278 . "Message canceled with Banana";
279 if ($this->nntp
->post($msg)) {
280 $this->spool
->delid($id);
282 header("Location: ?group=$group&first=$id");
284 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
288 function action_newFup($group, $id = -1)
290 $subject = $body = '';
294 $this->nntp
->group($group);
295 $this->_newPost($id);
297 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
298 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
299 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
305 $cuts = displayshortcuts();
306 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
307 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
308 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
309 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
310 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
311 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
312 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
313 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
314 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
315 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
316 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
317 . to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
318 if ($this->can_attach
) {
319 $html .= '<tr><th colspan="2">'._b_('Pièce jointe').'</th></tr>';
320 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
321 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
323 $html .= '<tr><th colspan="2">';
325 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
327 $html .= '<input type="hidden" name="action" value="new" />';
328 $html .= '<input type="submit" /></th></tr>';
329 $html .= '</table></form>';
334 function action_doFup($group, $artid = -1)
336 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
337 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
339 foreach(array('subject', 'name', 'org', 'body') as $key) {
340 $_POST[$key] = utf8_encode($_POST[$key]);
344 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
345 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
346 $msg = 'From: '.$this->profile
['name']."\n"
347 . "Newsgroups: ".$_POST['newsgroups']."\n"
348 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
349 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
350 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
353 $this->_require('post');
354 $post = new BananaPost($artid);
355 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
356 $msg .= "References: $refs{$post->headers['message-id']}\n";
359 $body_headers = $this->custom_plain
;
360 $body = wrap($body, "", $this->wrap
);
362 // include attachment in the body
363 $uploaded = $this->_upload('newpj');
364 switch ($uploaded['error']) {
366 $this->custom
= $this->custom_mp
.$this->custom
;
367 $body = $this->_make_part($body_headers, $body);
368 $file_head = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n"
369 . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n"
370 . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
371 $body .= $this->_make_part($file_head, $uploaded['data']);
372 $body .= "\n--".$this->boundary
.'--';
375 case UPLOAD_ERR_INI_SIZE
: case UPLOAD_ERR_FORM_SIZE
:
376 return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ')
377 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
379 case UPLOAD_ERR_PARTIAL
:
380 return '<p class="error">'._b_('Erreur lors de l\'upload de ')
381 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
383 case UPLOAD_ERR_NO_FILE
:
384 return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ')
385 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
387 case UPLOAD_ERR_NO_TMP_DIR
:
388 return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ')
389 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
392 $this->custom
= $body_headers.$this->custom
;
395 // finalise and post the message
396 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
398 if ($this->nntp
->post($msg)) {
399 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
401 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
405 /**************************************************************************/
406 /* Private functions */
407 /**************************************************************************/
409 function _newSpool($group, $disp=0, $since='') {
410 $this->_require('spool');
411 if (!$this->spool ||
$this->spool
->group
!= $group) {
412 $this->spool
= new BananaSpool($group, $disp, $since);
416 function _newPost($id)
418 $this->_require('post');
419 $this->post
= new BananaPost($id);
424 $this->_require('groups');
425 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
426 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
427 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
431 function _require($file)
433 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
436 function _upload($file)
438 if ($_FILES[$file]['name'] == "") {
439 return Array( 'error' => -1 );
443 $_FILES[$file]['tmp_name'];
445 // test if upload is ok
446 $file = $_FILES[$file];
447 if ($file['size'] == 0 ||
$file['error'] != 0) {
448 if ($file['error'] == 0) {
454 // adding custum data
455 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
457 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
461 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
462 if ($encod == 'base64') {
463 $data = chunk_split(base64_encode($data));
465 $file['name'] = basename($file['name']);
466 $file['type'] = $mime;
467 $file['encoding'] = $encod;
468 $file['data'] = $data;
473 function _make_part($headers, $body)
475 return "\n--".$this->boundary
."\n".$headers."\n".$body;