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')
63 Banana
::_require('misc');
64 $banana = new $class();
67 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
70 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
71 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
72 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
73 $banana->state
= Array ('group' => $group, 'artid' => $artid);
75 if (is_null($group)) {
77 if (isset($_GET['subscribe'])) {
78 return $banana->action_listSubs();
79 } elseif (isset($_POST['subscribe'])) {
80 $banana->action_saveSubs();
82 return $banana->action_listGroups();
84 } elseif (is_null($artid)) {
85 if (isset($_POST['action']) && $_POST['action'] == 'new') {
86 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
87 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
88 return $banana->action_newFup($group);
90 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
95 if (isset($_POST['action']) && $_POST['action']=='cancel') {
96 $res = $banana->action_cancelArticle($group, $artid);
101 if (isset($_GET['action'])) {
102 switch ($_GET['action']) {
104 $res .= $banana->action_showArticle($group, $artid, $partid);
105 if ($banana->post
->checkcancel()) {
106 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
107 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
108 . '<input type="hidden" name="action" value="cancel" />'
109 . '<input type="submit" value="Annuler !" />'
116 return $banana->action_newFup($group, $artid);
120 if (isset($_GET['pj'])) {
122 if (isset($_GET['action']) && $_GET['action'] == 'view') {
125 return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
128 return $res . $banana->action_showArticle($group, $artid, $partid);
132 /**************************************************************************/
134 /**************************************************************************/
136 function action_saveSubs()
141 function action_listGroups()
145 $cuts = displayshortcuts();
146 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
147 if (count($this->newgroups
->overview
)) {
148 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
149 $res .= $this->newgroups
->to_html();
156 function action_listSubs()
158 $this->_require('groups');
159 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
161 $cuts = displayshortcuts();
162 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
168 function action_showThread($group, $first)
170 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
172 if ($first > count($this->spool
->overview
)) {
173 $first = count($this->spool
->overview
);
176 $first = $first - ($first %
$this->tmax
) +
1;
178 $cuts = displayshortcuts($first);
180 $res = '<h1>'.$group.'</h1>'.$cuts;
181 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
188 function action_showArticle($group, $id, $part)
190 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
191 $this->_newPost($id);
193 if ($this->nntp
->lasterrorcode
== "423") {
194 $this->spool
->delid($id);
197 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
200 $cuts = displayshortcuts();
201 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
202 $res .= $this->post
->to_html($part);
209 function action_getAttachment($group, $id, $pjid, $action)
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>';
222 if ($this->post
->get_attachment($pjid, $action)) {
225 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
229 function action_cancelArticle($group, $id)
231 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
232 $this->_newPost($id);
233 $mid = array_search($id, $this->spool
->ids
);
235 if (!$this->post
->checkcancel()) {
236 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
238 $msg = 'From: '.$this->profile
['name']."\n"
239 . "Newsgroups: $group\n"
240 . "Subject: cmsg $mid\n"
242 . "Control: cancel $mid\n"
244 . "Message canceled with Banana";
245 if ($this->nntp
->post($msg)) {
246 $this->spool
->delid($id);
248 header("Location: ?group=$group&first=$id");
250 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
254 function action_newFup($group, $id = -1)
256 $subject = $body = '';
260 $this->nntp
->group($group);
261 $this->_newPost($id);
263 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
264 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
265 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
271 $cuts = displayshortcuts();
272 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
273 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
274 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
275 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
276 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
277 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
278 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
279 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
280 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
281 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
282 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
283 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
284 $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
285 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
286 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
287 $html .= '<tr><th colspan="2">';
289 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
291 $html .= '<input type="hidden" name="action" value="new" />';
292 $html .= '<input type="submit" /></th></tr>';
293 $html .= '</table></form>';
298 function action_doFup($group, $artid = -1)
300 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
301 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
303 foreach(array('subject', 'name', 'org', 'body') as $key) {
304 $_POST[$key] = utf8_encode($_POST[$key]);
308 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
309 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
310 $msg = 'From: '.$this->profile
['name']."\n"
311 . "Newsgroups: ".$_POST['newsgroups']."\n"
312 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
313 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
314 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
317 $this->_require('post');
318 $post = new BananaPost($artid);
319 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
320 $msg .= "References: $refs{$post->headers['message-id']}\n";
323 $body = wrap($body, "", $this->wrap
);
325 // include attachment in the body
326 $uploaded = $this->_upload('newpj');
327 if ($uploaded['error'] == 0) {
328 $this->custom
= $this->custom_mp
;
329 $body = "\n--".$this->boundary
."\n".$this->custom_bd
."\n\n".$body."\n--".$this->boundary
."\n";
331 $body .= 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n";
332 $body .= 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n\n";
333 $body .= 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
334 $body .= $uploaded['data'];
335 $body .= '--'.$this->boundary
.'--';
337 #TODO:afficher les erreurs lorsque l'upload ne marche pas
339 // finalise and post the message
340 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
342 if ($this->nntp
->post($msg)) {
343 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
345 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
349 /**************************************************************************/
350 /* Private functions */
351 /**************************************************************************/
353 function _newSpool($group, $disp=0, $since='') {
354 $this->_require('spool');
355 if (!$this->spool ||
$this->spool
->group
!= $group) {
356 $this->spool
= new BananaSpool($group, $disp, $since);
360 function _newPost($id)
362 $this->_require('post');
363 $this->post
= new BananaPost($id);
368 $this->_require('groups');
369 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
370 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
371 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
375 function _require($file)
377 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
380 function _upload($file)
382 if ($_FILES[$file]['name'] == "") {
383 return Array( 'error' => -1 );
387 $_FILES[$file]['tmp_name'];
389 // test if upload is ok
390 $file = $_FILES[$file];
391 if ($file['size'] == 0 ||
$file['error'] != 0) {
392 if ($file['error'] == 0) {
398 // adding custum data
399 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
401 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
405 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
406 if ($encod == 'base64') {
407 $data = chunk_split(base64_encode($data));
409 $file['name'] = basename($file['name']);
410 $file['type'] = $mime;
411 $file['encoding'] = $encod;
412 $file['data'] = $data;