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 posting html messages is allowed
30 var $can_html = false
;
32 /** Regexp for selecting newsgroups to show (if empty, match all newsgroups)
33 * ex : '^xorg\..*' for xorg.*
43 /** Boundary for multipart messages
45 var $boundary = "bananaBoundary42";
46 /** Global headers to use for text/plain messages
48 var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
49 /** Global headers to use from multipart messages
51 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\nUser-Agent: Banana @VERSION@\n";
52 /** Body part headers to use from multipart messages
54 var $custom_bd = "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit";
56 /** News serveur to use
58 var $host = 'news://localhost:119/';
62 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
63 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
65 var $state = Array('group' => null
, 'artid' => null
);
74 $this->_require('NetNNTP');
75 setlocale(LC_ALL
, $this->profile
['locale']);
76 $this->nntp
= new nntp($this->host
);
79 function run($class = 'Banana')
83 Banana
::_require('misc');
84 $banana = new $class();
87 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
90 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
91 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
92 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
93 $banana->state
= Array ('group' => $group, 'artid' => $artid);
95 if (is_null($group)) {
97 if (isset($_GET['subscribe'])) {
98 return $banana->action_listSubs();
99 } elseif (isset($_POST['subscribe'])) {
100 $banana->action_saveSubs();
102 return $banana->action_listGroups();
104 } elseif (is_null($artid)) {
105 if (isset($_POST['action']) && $_POST['action'] == 'new') {
106 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
107 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
108 return $banana->action_newFup($group);
110 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
115 if (isset($_POST['action']) && $_POST['action']=='cancel') {
116 $res = $banana->action_cancelArticle($group, $artid);
121 if (isset($_GET['action'])) {
122 switch ($_GET['action']) {
124 $res .= $banana->action_showArticle($group, $artid, $partid);
125 if ($banana->post
->checkcancel()) {
126 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
127 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
128 . '<input type="hidden" name="action" value="cancel" />'
129 . '<input type="submit" value="Annuler !" />'
136 return $banana->action_newFup($group, $artid);
140 if (isset($_GET['pj'])) {
142 if (isset($_GET['action']) && $_GET['action'] == 'view') {
145 $att = $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
152 return $res . $banana->action_showArticle($group, $artid, $partid);
156 /**************************************************************************/
158 /**************************************************************************/
160 function action_saveSubs()
165 function action_listGroups()
169 $cuts = displayshortcuts();
170 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
171 if (count($this->newgroups
->overview
)) {
172 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
173 $res .= $this->newgroups
->to_html();
180 function action_listSubs()
182 $this->_require('groups');
183 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
185 $cuts = displayshortcuts();
186 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
192 function action_showThread($group, $first)
194 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
196 if ($first > count($this->spool
->overview
)) {
197 $first = count($this->spool
->overview
);
200 $first = $first - ($first %
$this->tmax
) +
1;
202 $cuts = displayshortcuts($first);
204 $res = '<h1>'.$group.'</h1>'.$cuts;
205 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
212 function action_showArticle($group, $id, $part)
214 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
215 $this->_newPost($id);
217 if ($this->nntp
->lasterrorcode
== "423") {
218 $this->spool
->delid($id);
221 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
224 $cuts = displayshortcuts();
225 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
226 $res .= $this->post
->to_html($part);
233 function action_getAttachment($group, $id, $pjid, $action)
235 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
236 $this->_newPost($id);
238 if ($this->nntp
->lasterrorcode
== "423") {
239 $this->spool
->delid($id);
242 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
246 if ($this->post
->get_attachment($pjid, $action)) {
249 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
253 function action_cancelArticle($group, $id)
255 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
256 $this->_newPost($id);
257 $mid = array_search($id, $this->spool
->ids
);
259 if (!$this->post
->checkcancel()) {
260 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
262 $msg = 'From: '.$this->profile
['name']."\n"
263 . "Newsgroups: $group\n"
264 . "Subject: cmsg $mid\n"
266 . "Control: cancel $mid\n"
268 . "Message canceled with Banana";
269 if ($this->nntp
->post($msg)) {
270 $this->spool
->delid($id);
272 header("Location: ?group=$group&first=$id");
274 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
278 function action_newFup($group, $id = -1)
280 $subject = $body = '';
284 $this->nntp
->group($group);
285 $this->_newPost($id);
287 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
288 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
289 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
295 $cuts = displayshortcuts();
296 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
297 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
298 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
299 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
300 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
301 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
302 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
303 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
304 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
305 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
306 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
307 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
308 $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
309 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
310 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
311 $html .= '<tr><th colspan="2">';
313 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
315 $html .= '<input type="hidden" name="action" value="new" />';
316 $html .= '<input type="submit" /></th></tr>';
317 $html .= '</table></form>';
322 function action_doFup($group, $artid = -1)
324 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
325 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
327 foreach(array('subject', 'name', 'org', 'body') as $key) {
328 $_POST[$key] = utf8_encode($_POST[$key]);
332 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
333 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
334 $msg = 'From: '.$this->profile
['name']."\n"
335 . "Newsgroups: ".$_POST['newsgroups']."\n"
336 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
337 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
338 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
341 $this->_require('post');
342 $post = new BananaPost($artid);
343 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
344 $msg .= "References: $refs{$post->headers['message-id']}\n";
347 $body = wrap($body, "", $this->wrap
);
349 // include attachment in the body
350 $uploaded = $this->_upload('newpj');
351 switch ($uploaded['error']) {
353 $this->custom
= $this->custom_mp
;
354 $body = "\n--".$this->boundary
."\n".$this->custom_bd
."\n\n".$body."\n--".$this->boundary
."\n";
356 $body .= 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n";
357 $body .= 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n\n";
358 $body .= 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
359 $body .= $uploaded['data'];
360 $body .= '--'.$this->boundary
.'--';
363 case UPLOAD_ERR_INI_SIZE
: case UPLOAD_ERR_FORM_SIZE
:
364 return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ')
365 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
367 case UPLOAD_ERR_PARTIAL
:
368 return '<p class="error">'._b_('Erreur lors de l\'upload de ')
369 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
371 case UPLOAD_ERR_NO_FILE
:
372 return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ')
373 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
375 case UPLOAD_ERR_NO_TMP_DIR
:
376 return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ')
377 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
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;