c45d717f0dd4c3612a39f244898cb316b4731dc9
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');
30 var $boundary = "bananaBoundary42";
31 var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
32 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\nUser-Agent: Banana @VERSION@\n";
33 var $custom_bd = "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit";
35 var $host = 'news://localhost:119/';
37 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
38 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
40 var $state = Array('group' => null
, 'artid' => null
);
49 $this->_require('NetNNTP');
50 setlocale(LC_ALL
, $this->profile
['locale']);
51 $this->nntp
= new nntp($this->host
);
54 function run($class = 'Banana')
57 Banana
::_require('misc');
58 $banana = new $class();
61 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
64 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
65 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
66 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
67 $banana->state
= Array ('group' => $group, 'artid' => $artid);
69 if (is_null($group)) {
71 if (isset($_GET['subscribe'])) {
72 return $banana->action_listSubs();
73 } elseif (isset($_POST['subscribe'])) {
74 $banana->action_saveSubs();
76 return $banana->action_listGroups();
78 } elseif (is_null($artid)) {
79 if (isset($_POST['action']) && $_POST['action'] == 'new') {
80 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
81 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
82 return $banana->action_newFup($group);
84 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
89 if (isset($_POST['action']) && $_POST['action']=='cancel') {
90 $res = $banana->action_cancelArticle($group, $artid);
95 if (isset($_GET['action'])) {
96 switch ($_GET['action']) {
98 $res .= $banana->action_showArticle($group, $artid, $partid);
99 if ($banana->post
->checkcancel()) {
100 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
101 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
102 . '<input type="hidden" name="action" value="cancel" />'
103 . '<input type="submit" value="Annuler !" />'
110 return $banana->action_newFup($group, $artid);
114 if (isset($_GET['pj'])) {
116 if (isset($_GET['action']) && $_GET['action'] == 'view') {
119 return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
122 return $res . $banana->action_showArticle($group, $artid, $partid);
126 /**************************************************************************/
128 /**************************************************************************/
130 function action_saveSubs()
135 function action_listGroups()
139 $cuts = displayshortcuts();
140 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
141 if (count($this->newgroups
->overview
)) {
142 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
143 $res .= $this->newgroups
->to_html();
150 function action_listSubs()
152 $this->_require('groups');
153 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
155 $cuts = displayshortcuts();
156 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
162 function action_showThread($group, $first)
164 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
166 if ($first > count($this->spool
->overview
)) {
167 $first = count($this->spool
->overview
);
170 $first = $first - ($first %
$this->tmax
) +
1;
172 $cuts = displayshortcuts($first);
174 $res = '<h1>'.$group.'</h1>'.$cuts;
175 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
182 function action_showArticle($group, $id, $part)
184 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
185 $this->_newPost($id);
187 if ($this->nntp
->lasterrorcode
== "423") {
188 $this->spool
->delid($id);
191 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
194 $cuts = displayshortcuts();
195 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
196 $res .= $this->post
->to_html($part);
203 function action_getAttachment($group, $id, $pjid, $action)
205 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
206 $this->_newPost($id);
208 if ($this->nntp
->lasterrorcode
== "423") {
209 $this->spool
->delid($id);
212 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
216 if ($this->post
->get_attachment($pjid, $action)) {
219 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
223 function action_cancelArticle($group, $id)
225 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
226 $this->_newPost($id);
227 $mid = array_search($id, $this->spool
->ids
);
229 if (!$this->post
->checkcancel()) {
230 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
232 $msg = 'From: '.$this->profile
['name']."\n"
233 . "Newsgroups: $group\n"
234 . "Subject: cmsg $mid\n"
236 . "Control: cancel $mid\n"
238 . "Message canceled with Banana";
239 if ($this->nntp
->post($msg)) {
240 $this->spool
->delid($id);
242 header("Location: ?group=$group&first=$id");
244 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
248 function action_newFup($group, $id = -1)
250 $subject = $body = '';
254 $this->nntp
->group($group);
255 $this->_newPost($id);
257 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
258 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
259 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
265 $cuts = displayshortcuts();
266 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
267 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
268 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
269 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
270 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
271 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
272 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
273 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
274 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
275 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
276 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
277 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
278 $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
279 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
280 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
281 $html .= '<tr><th colspan="2">';
283 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
285 $html .= '<input type="hidden" name="action" value="new" />';
286 $html .= '<input type="submit" /></th></tr>';
287 $html .= '</table></form>';
292 function action_doFup($group, $artid = -1)
294 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
295 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
297 foreach(array('subject', 'name', 'org', 'body') as $key) {
298 $_POST[$key] = utf8_encode($_POST[$key]);
302 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
303 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
304 $msg = 'From: '.$this->profile
['name']."\n"
305 . "Newsgroups: ".$_POST['newsgroups']."\n"
306 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
307 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
308 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
311 $this->_require('post');
312 $post = new BananaPost($artid);
313 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
314 $msg .= "References: $refs{$post->headers['message-id']}\n";
317 $body = wrap($body, "", $this->wrap
);
319 // include attachment in the body
320 $uploaded = $this->_upload('newpj');
321 if ($uploaded['error'] == 0) {
322 $this->custom
= $this->custom_mp
;
323 $body = "\n--".$this->boundary
."\n".$this->custom_bd
."\n\n".$body."\n--".$this->boundary
."\n";
325 $body .= 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n";
326 $body .= 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n\n";
327 $body .= 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
328 $body .= $uploaded['data'];
329 $body .= '--'.$this->boundary
.'--';
331 #TODO:afficher les erreurs lorsque l'upload ne marche pas
333 // finalise and post the message
334 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
336 if ($this->nntp
->post($msg)) {
337 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
339 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
343 /**************************************************************************/
344 /* Private functions */
345 /**************************************************************************/
347 function _newSpool($group, $disp=0, $since='') {
348 $this->_require('spool');
349 if (!$this->spool ||
$this->spool
->group
!= $group) {
350 $this->spool
= new BananaSpool($group, $disp, $since);
354 function _newPost($id)
356 $this->_require('post');
357 $this->post
= new BananaPost($id);
362 $this->_require('groups');
363 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
364 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
365 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
369 function _require($file)
371 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
374 function _upload($file)
376 if ($_FILES[$file]['name'] == "") {
377 return Array( 'error' => -1 );
381 $_FILES[$file]['tmp_name'];
383 // test if upload is ok
384 $file = $_FILES[$file];
385 if ($file['size'] == 0 ||
$file['error'] != 0) {
386 if ($file['error'] == 0) {
392 // adding custum data
393 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
395 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
399 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
400 if ($encod == 'base64') {
401 $data = chunk_split(base64_encode($data));
403 $file['name'] = basename($file['name']);
404 $file['type'] = $mime;
405 $file['encoding'] = $encod;
406 $file['data'] = $data;