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 /** Boundary for multipart messages
42 var $boundary = 'bananaBoundary42';
43 /** Global headers to use for messages
45 var $custom = "Mime-Version: 1.0\nUser-Agent: Banana @VERSION@\n";
46 /** Global headers to use from multipart messages
48 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\n";
49 /** Body type when using plain text
51 var $custom_plain= "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit\n";
53 /** News serveur to use
55 var $host = 'news://localhost:119/';
59 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
60 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
62 var $state = Array('group' => null
, 'artid' => null
);
71 $this->_require('NetNNTP');
72 setlocale(LC_ALL
, $this->profile
['locale']);
73 $this->nntp
= new nntp($this->host
);
76 function run($class = 'Banana')
80 Banana
::_require('misc');
81 $banana = new $class();
84 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
87 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
88 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
89 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
90 $banana->state
= Array ('group' => $group, 'artid' => $artid);
92 if (is_null($group)) {
94 if (isset($_GET['subscribe'])) {
95 return $banana->action_listSubs();
96 } elseif (isset($_POST['subscribe'])) {
97 $banana->action_saveSubs();
99 return $banana->action_listGroups();
101 } elseif (is_null($artid)) {
102 if (isset($_POST['action']) && $_POST['action'] == 'new') {
103 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
104 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
105 return $banana->action_newFup($group);
107 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
112 if (isset($_POST['action']) && $_POST['action']=='cancel') {
113 $res = $banana->action_cancelArticle($group, $artid);
118 if (isset($_GET['action'])) {
119 switch ($_GET['action']) {
121 $res .= $banana->action_showArticle($group, $artid, $partid);
122 if ($banana->post
->checkcancel()) {
123 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
124 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
125 . '<input type="hidden" name="action" value="cancel" />'
126 . '<input type="submit" value="Annuler !" />'
133 return $banana->action_newFup($group, $artid);
137 if (isset($_GET['pj'])) {
139 if (isset($_GET['action']) && $_GET['action'] == 'view') {
142 $att = $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
149 return $res . $banana->action_showArticle($group, $artid, $partid);
153 /**************************************************************************/
155 /**************************************************************************/
157 function action_saveSubs()
162 function action_listGroups()
166 $cuts = displayshortcuts();
167 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
168 if (count($this->newgroups
->overview
)) {
169 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
170 $res .= $this->newgroups
->to_html();
177 function action_listSubs()
179 $this->_require('groups');
180 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
182 $cuts = displayshortcuts();
183 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
189 function action_showThread($group, $first)
191 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
193 if ($first > count($this->spool
->overview
)) {
194 $first = count($this->spool
->overview
);
197 $first = $first - ($first %
$this->tmax
) +
1;
199 $cuts = displayshortcuts($first);
201 $res = '<h1>'.$group.'</h1>'.$cuts;
202 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
209 function action_showArticle($group, $id, $part)
211 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
212 $this->_newPost($id);
214 if ($this->nntp
->lasterrorcode
== "423") {
215 $this->spool
->delid($id);
218 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
221 $cuts = displayshortcuts();
222 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
223 $res .= $this->post
->to_html($part);
230 function action_getAttachment($group, $id, $pjid, $action)
232 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
233 $this->_newPost($id);
235 if ($this->nntp
->lasterrorcode
== "423") {
236 $this->spool
->delid($id);
239 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
243 if ($this->post
->get_attachment($pjid, $action)) {
246 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
250 function action_cancelArticle($group, $id)
252 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
253 $this->_newPost($id);
254 $mid = array_search($id, $this->spool
->ids
);
256 if (!$this->post
->checkcancel()) {
257 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
259 $msg = 'From: '.$this->profile
['name']."\n"
260 . "Newsgroups: $group\n"
261 . "Subject: cmsg $mid\n"
263 . "Control: cancel $mid\n"
265 . "Message canceled with Banana";
266 if ($this->nntp
->post($msg)) {
267 $this->spool
->delid($id);
269 header("Location: ?group=$group&first=$id");
271 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
275 function action_newFup($group, $id = -1)
277 $subject = $body = '';
281 $this->nntp
->group($group);
282 $this->_newPost($id);
284 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
285 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
286 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
292 $cuts = displayshortcuts();
293 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
294 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
295 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
296 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
297 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
298 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
299 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
300 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
301 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
302 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
303 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
304 . to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
305 $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
306 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
307 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
308 $html .= '<tr><th colspan="2">';
310 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
312 $html .= '<input type="hidden" name="action" value="new" />';
313 $html .= '<input type="submit" /></th></tr>';
314 $html .= '</table></form>';
319 function action_doFup($group, $artid = -1)
321 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
322 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
324 foreach(array('subject', 'name', 'org', 'body') as $key) {
325 $_POST[$key] = utf8_encode($_POST[$key]);
329 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
330 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
331 $msg = 'From: '.$this->profile
['name']."\n"
332 . "Newsgroups: ".$_POST['newsgroups']."\n"
333 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
334 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
335 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
338 $this->_require('post');
339 $post = new BananaPost($artid);
340 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
341 $msg .= "References: $refs{$post->headers['message-id']}\n";
344 $body_headers = $this->custom_plain
;
345 $body = wrap($body, "", $this->wrap
);
347 // include attachment in the body
348 $uploaded = $this->_upload('newpj');
349 switch ($uploaded['error']) {
351 $this->custom
= $this->custom_mp
.$this->custom
;
352 $body = $this->_make_part($body_headers, $body);
353 $file_head = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n"
354 . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n"
355 . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
356 $body .= $this->_make_part($file_head, $uploaded['data']);
357 $body .= "\n--".$this->boundary
.'--';
360 case UPLOAD_ERR_INI_SIZE
: case UPLOAD_ERR_FORM_SIZE
:
361 return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ')
362 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
364 case UPLOAD_ERR_PARTIAL
:
365 return '<p class="error">'._b_('Erreur lors de l\'upload de ')
366 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
368 case UPLOAD_ERR_NO_FILE
:
369 return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ')
370 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
372 case UPLOAD_ERR_NO_TMP_DIR
:
373 return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ')
374 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
377 $this->custom
= $body_headers.$this->custom
;
380 // finalise and post the message
381 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
383 if ($this->nntp
->post($msg)) {
384 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
386 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
390 /**************************************************************************/
391 /* Private functions */
392 /**************************************************************************/
394 function _newSpool($group, $disp=0, $since='') {
395 $this->_require('spool');
396 if (!$this->spool ||
$this->spool
->group
!= $group) {
397 $this->spool
= new BananaSpool($group, $disp, $since);
401 function _newPost($id)
403 $this->_require('post');
404 $this->post
= new BananaPost($id);
409 $this->_require('groups');
410 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
411 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
412 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
416 function _require($file)
418 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
421 function _upload($file)
423 if ($_FILES[$file]['name'] == "") {
424 return Array( 'error' => -1 );
428 $_FILES[$file]['tmp_name'];
430 // test if upload is ok
431 $file = $_FILES[$file];
432 if ($file['size'] == 0 ||
$file['error'] != 0) {
433 if ($file['error'] == 0) {
439 // adding custum data
440 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
442 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
446 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
447 if ($encod == 'base64') {
448 $data = chunk_split(base64_encode($data));
450 $file['name'] = basename($file['name']);
451 $file['type'] = $mime;
452 $file['encoding'] = $encod;
453 $file['data'] = $data;
458 function _make_part($headers, $body)
460 return "\n--".$this->boundary
."\n".$headers."\n".$body;