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;
28 /** Indicate wether x-face should be skinned as specials data or not
30 var $formatxface = true
;
32 /** Regexp for selecting newsgroups to show (if empty, match all newsgroups)
33 * ex : '^xorg\..*' for xorg.*
43 * Should be included in a regexp delimited using ! (eg: "!$url_regexp!i")
44 * If it matches, return 3 main parts :
45 * \\1 and \\3 are delimiters
48 * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches);
50 * $matches[2] = "http://www.polytechnique.org"
53 var $url_regexp = '(["\[])?((?:https?|ftp|news)://(?:&|[a-z@0-9.~%$£µ&i#\-+=_/\?])*)(["\]])?';
56 /** Boundary for multipart messages
58 var $boundary = 'bananaBoundary42';
59 /** Global headers to use for messages
61 var $custom = "Mime-Version: 1.0\nUser-Agent: Banana @VERSION@\n";
62 /** Global headers to use from multipart messages
64 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\n";
65 /** Body type when using plain text
67 var $custom_plain= "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit\n";
69 /** News serveur to use
71 var $host = 'news://localhost:119/';
75 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
76 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
78 var $state = Array('group' => null
, 'artid' => null
);
87 $this->_require('NetNNTP');
88 setlocale(LC_ALL
, $this->profile
['locale']);
89 $this->nntp
= new nntp($this->host
);
92 function run($class = 'Banana')
96 Banana
::_require('misc');
97 $banana = new $class();
100 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
103 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
104 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
105 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
106 $banana->state
= Array ('group' => $group, 'artid' => $artid);
108 if (is_null($group)) {
109 if (isset($_GET['subscribe'])) {
110 return $banana->action_listSubs();
111 } elseif (isset($_POST['subscribe'])) {
112 $banana->action_saveSubs();
114 return $banana->action_listGroups();
116 } elseif (is_null($artid)) {
117 if (isset($_POST['action']) && $_POST['action'] == 'new') {
118 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
119 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
120 return $banana->action_newFup($group);
122 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
126 if (isset($_POST['action']) && $_POST['action']=='cancel') {
127 $res = $banana->action_cancelArticle($group, $artid);
132 if (isset($_GET['action'])) {
133 switch ($_GET['action']) {
135 $res .= $banana->action_showArticle($group, $artid, $partid);
136 if ($banana->post
->checkcancel()) {
137 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
138 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
139 . '<input type="hidden" name="action" value="cancel" />'
140 . '<input type="submit" value="Annuler !" />'
147 return $banana->action_newFup($group, $artid);
151 if (isset($_GET['pj'])) {
153 if (isset($_GET['action']) && $_GET['action'] == 'view') {
156 $att = $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
163 return $res . $banana->action_showArticle($group, $artid, $partid);
167 /**************************************************************************/
169 /**************************************************************************/
171 function action_saveSubs()
176 function action_listGroups()
180 $cuts = displayshortcuts();
181 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
182 if (count($this->newgroups
->overview
)) {
183 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
184 $res .= $this->newgroups
->to_html();
191 function action_listSubs()
193 $this->_require('groups');
194 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
196 $cuts = displayshortcuts();
197 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
203 function action_showThread($group, $first)
205 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
207 if ($first > count($this->spool
->overview
)) {
208 $first = count($this->spool
->overview
);
211 $first = $first - ($first %
$this->tmax
) +
1;
213 $cuts = displayshortcuts($first);
215 $res = '<h1>'.$group.'</h1>'.$cuts;
216 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
223 function action_showArticle($group, $id, $part)
225 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
226 $this->_newPost($id);
228 if ($this->nntp
->lasterrorcode
== "423") {
229 $this->spool
->delid($id);
232 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
235 $cuts = displayshortcuts();
236 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
237 $res .= $this->post
->to_html($part);
244 function action_getAttachment($group, $id, $pjid, $action)
246 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
247 $this->_newPost($id);
249 if ($this->nntp
->lasterrorcode
== "423") {
250 $this->spool
->delid($id);
253 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
257 if ($this->post
->get_attachment($pjid, $action)) {
260 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
264 function action_cancelArticle($group, $id)
266 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
267 $this->_newPost($id);
268 $mid = array_search($id, $this->spool
->ids
);
270 if (!$this->post
->checkcancel()) {
271 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
273 $msg = 'From: '.$this->profile
['name']."\n"
274 . "Newsgroups: $group\n"
275 . "Subject: cmsg $mid\n"
277 . "Control: cancel $mid\n"
279 . "Message canceled with Banana";
280 if ($this->nntp
->post($msg)) {
281 $this->spool
->delid($id);
283 header("Location: ?group=$group&first=$id");
285 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
289 function action_newFup($group, $id = -1)
291 $subject = $body = '';
295 $this->nntp
->group($group);
296 $this->_newPost($id);
298 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
299 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
300 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
306 $cuts = displayshortcuts();
307 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
308 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
309 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
310 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
311 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
312 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
313 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
314 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
315 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
316 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
317 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
318 . to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
319 if ($this->can_attach
) {
320 $html .= '<tr><th colspan="2">'._b_('Pièce jointe').'</th></tr>';
321 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
322 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
324 $html .= '<tr><th colspan="2">';
326 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
328 $html .= '<input type="hidden" name="action" value="new" />';
329 $html .= '<input type="submit" /></th></tr>';
330 $html .= '</table></form>';
335 function action_doFup($group, $artid = -1)
337 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
338 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
340 foreach(array('subject', 'name', 'org', 'body') as $key) {
341 $_POST[$key] = utf8_encode($_POST[$key]);
345 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
346 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
347 $msg = 'From: '.$this->profile
['name']."\n"
348 . "Newsgroups: ".$_POST['newsgroups']."\n"
349 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
350 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
351 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
354 $this->_require('post');
355 $post = new BananaPost($artid);
356 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
357 $msg .= "References: $refs{$post->headers['message-id']}\n";
360 $body_headers = $this->custom_plain
;
361 $body = wrap($body, "");
363 // include attachment in the body
364 $uploaded = $this->_upload('newpj');
365 switch ($uploaded['error']) {
367 $this->custom
= $this->custom_mp
.$this->custom
;
368 $body = $this->_make_part($body_headers, $body);
369 $file_head = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n"
370 . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n"
371 . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
372 $body .= $this->_make_part($file_head, $uploaded['data']);
373 $body .= "\n--".$this->boundary
.'--';
376 case UPLOAD_ERR_INI_SIZE
: case UPLOAD_ERR_FORM_SIZE
:
377 return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ')
378 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
380 case UPLOAD_ERR_PARTIAL
:
381 return '<p class="error">'._b_('Erreur lors de l\'upload de ')
382 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
384 case UPLOAD_ERR_NO_FILE
:
385 return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ')
386 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
388 case UPLOAD_ERR_NO_TMP_DIR
:
389 return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ')
390 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
393 $this->custom
= $body_headers.$this->custom
;
396 // finalise and post the message
397 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
399 if ($this->nntp
->post($msg)) {
400 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
402 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
406 /**************************************************************************/
407 /* Private functions */
408 /**************************************************************************/
410 function _newSpool($group, $disp=0, $since='') {
411 $this->_require('spool');
412 if (!$this->spool ||
$this->spool
->group
!= $group) {
413 $this->spool
= new BananaSpool($group, $disp, $since);
417 function _newPost($id)
419 $this->_require('post');
420 $this->post
= new BananaPost($id);
425 $this->_require('groups');
426 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
427 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
428 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
432 function _require($file)
434 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
437 function _upload($file)
439 if ($_FILES[$file]['name'] == "") {
440 return Array( 'error' => -1 );
444 $_FILES[$file]['tmp_name'];
446 // test if upload is ok
447 $file = $_FILES[$file];
448 if ($file['size'] == 0 ||
$file['error'] != 0) {
449 if ($file['error'] == 0) {
455 // adding custum data
456 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
458 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
462 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
463 if ($encod == 'base64') {
464 $data = chunk_split(base64_encode($data));
466 $file['name'] = basename($file['name']);
467 $file['type'] = $mime;
468 $file['encoding'] = $encod;
469 $file['data'] = $data;
474 function _make_part($headers, $body)
476 return "\n--".$this->boundary
."\n".$headers."\n".$body;