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 ********************************************************************************/
13 var $maxfilesize = 100000;
15 var $hdecode = array('from','name','organization','subject');
16 var $parse_hdr = array('content-disposition', 'content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
17 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
18 var $show_hdr = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
20 /** Favorites MIMEtypes to use, by order for reading multipart messages
22 var $body_mime = array('text/plain', 'text/html', 'text/richtext');
24 /** Regexp for selecting newsgroups to show (if empty, match all newsgroups)
25 * ex : '^xorg\..*' for xorg.*
35 var $boundary = "bananaBoundary42";
36 var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
37 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\nUser-Agent: Banana @VERSION@\n";
38 var $custom_bd = "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit";
40 var $host = 'news://localhost:119/';
42 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
43 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
45 var $state = Array('group' => null
, 'artid' => null
);
54 $this->_require('NetNNTP');
55 setlocale(LC_ALL
, $this->profile
['locale']);
56 $this->nntp
= new nntp($this->host
);
59 function run($class = 'Banana')
62 Banana
::_require('misc');
63 $banana = new $class();
66 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
69 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
70 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
71 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
72 $banana->state
= Array ('group' => $group, 'artid' => $artid);
74 if (is_null($group)) {
76 if (isset($_GET['subscribe'])) {
77 return $banana->action_listSubs();
78 } elseif (isset($_POST['subscribe'])) {
79 $banana->action_saveSubs();
81 return $banana->action_listGroups();
83 } elseif (is_null($artid)) {
84 if (isset($_POST['action']) && $_POST['action'] == 'new') {
85 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
86 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
87 return $banana->action_newFup($group);
89 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
94 if (isset($_POST['action']) && $_POST['action']=='cancel') {
95 $res = $banana->action_cancelArticle($group, $artid);
100 if (isset($_GET['action'])) {
101 switch ($_GET['action']) {
103 $res .= $banana->action_showArticle($group, $artid, $partid);
104 if ($banana->post
->checkcancel()) {
105 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
106 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
107 . '<input type="hidden" name="action" value="cancel" />'
108 . '<input type="submit" value="Annuler !" />'
115 return $banana->action_newFup($group, $artid);
119 if (isset($_GET['pj'])) {
121 if (isset($_GET['action']) && $_GET['action'] == 'view') {
124 return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
127 return $res . $banana->action_showArticle($group, $artid, $partid);
131 /**************************************************************************/
133 /**************************************************************************/
135 function action_saveSubs()
140 function action_listGroups()
144 $cuts = displayshortcuts();
145 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
146 if (count($this->newgroups
->overview
)) {
147 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
148 $res .= $this->newgroups
->to_html();
155 function action_listSubs()
157 $this->_require('groups');
158 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
160 $cuts = displayshortcuts();
161 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
167 function action_showThread($group, $first)
169 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
171 if ($first > count($this->spool
->overview
)) {
172 $first = count($this->spool
->overview
);
175 $first = $first - ($first %
$this->tmax
) +
1;
177 $cuts = displayshortcuts($first);
179 $res = '<h1>'.$group.'</h1>'.$cuts;
180 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
187 function action_showArticle($group, $id, $part)
189 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
190 $this->_newPost($id);
192 if ($this->nntp
->lasterrorcode
== "423") {
193 $this->spool
->delid($id);
196 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
199 $cuts = displayshortcuts();
200 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
201 $res .= $this->post
->to_html($part);
208 function action_getAttachment($group, $id, $pjid, $action)
210 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
211 $this->_newPost($id);
213 if ($this->nntp
->lasterrorcode
== "423") {
214 $this->spool
->delid($id);
217 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
221 if ($this->post
->get_attachment($pjid, $action)) {
224 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
228 function action_cancelArticle($group, $id)
230 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
231 $this->_newPost($id);
232 $mid = array_search($id, $this->spool
->ids
);
234 if (!$this->post
->checkcancel()) {
235 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
237 $msg = 'From: '.$this->profile
['name']."\n"
238 . "Newsgroups: $group\n"
239 . "Subject: cmsg $mid\n"
241 . "Control: cancel $mid\n"
243 . "Message canceled with Banana";
244 if ($this->nntp
->post($msg)) {
245 $this->spool
->delid($id);
247 header("Location: ?group=$group&first=$id");
249 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
253 function action_newFup($group, $id = -1)
255 $subject = $body = '';
259 $this->nntp
->group($group);
260 $this->_newPost($id);
262 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
263 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
264 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
270 $cuts = displayshortcuts();
271 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
272 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
273 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
274 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
275 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
276 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
277 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
278 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
279 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
280 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
281 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
282 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
283 $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
284 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
285 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
286 $html .= '<tr><th colspan="2">';
288 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
290 $html .= '<input type="hidden" name="action" value="new" />';
291 $html .= '<input type="submit" /></th></tr>';
292 $html .= '</table></form>';
297 function action_doFup($group, $artid = -1)
299 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
300 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
302 foreach(array('subject', 'name', 'org', 'body') as $key) {
303 $_POST[$key] = utf8_encode($_POST[$key]);
307 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
308 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
309 $msg = 'From: '.$this->profile
['name']."\n"
310 . "Newsgroups: ".$_POST['newsgroups']."\n"
311 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
312 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
313 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
316 $this->_require('post');
317 $post = new BananaPost($artid);
318 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
319 $msg .= "References: $refs{$post->headers['message-id']}\n";
322 $body = wrap($body, "", $this->wrap
);
324 // include attachment in the body
325 $uploaded = $this->_upload('newpj');
326 if ($uploaded['error'] == 0) {
327 $this->custom
= $this->custom_mp
;
328 $body = "\n--".$this->boundary
."\n".$this->custom_bd
."\n\n".$body."\n--".$this->boundary
."\n";
330 $body .= 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n";
331 $body .= 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n\n";
332 $body .= 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
333 $body .= $uploaded['data'];
334 $body .= '--'.$this->boundary
.'--';
336 #TODO:afficher les erreurs lorsque l'upload ne marche pas
338 // finalise and post the message
339 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
341 if ($this->nntp
->post($msg)) {
342 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
344 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
348 /**************************************************************************/
349 /* Private functions */
350 /**************************************************************************/
352 function _newSpool($group, $disp=0, $since='') {
353 $this->_require('spool');
354 if (!$this->spool ||
$this->spool
->group
!= $group) {
355 $this->spool
= new BananaSpool($group, $disp, $since);
359 function _newPost($id)
361 $this->_require('post');
362 $this->post
= new BananaPost($id);
367 $this->_require('groups');
368 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
369 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
370 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
374 function _require($file)
376 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
379 function _upload($file)
381 if ($_FILES[$file]['name'] == "") {
382 return Array( 'error' => -1 );
386 $_FILES[$file]['tmp_name'];
388 // test if upload is ok
389 $file = $_FILES[$file];
390 if ($file['size'] == 0 ||
$file['error'] != 0) {
391 if ($file['error'] == 0) {
397 // adding custum data
398 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
400 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
404 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
405 if ($encod == 'base64') {
406 $data = chunk_split(base64_encode($data));
408 $file['name'] = basename($file['name']);
409 $file['type'] = $mime;
410 $file['encoding'] = $encod;
411 $file['data'] = $data;