d79bb042bd7cf10e58fc595c57d0951ebd12bf45
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');
27 var $boundary = "bananaBoundary42";
28 var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
29 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\nUser-Agent: Banana @VERSION@\n";
30 var $custom_bd = "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit";
32 var $host = 'news://localhost:119/';
34 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
35 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
37 var $state = Array('group' => null
, 'artid' => null
);
46 $this->_require('NetNNTP');
47 setlocale(LC_ALL
, $this->profile
['locale']);
48 $this->nntp
= new nntp($this->host
);
51 function run($class = 'Banana')
54 Banana
::_require('misc');
55 $banana = new $class();
58 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
61 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
62 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
63 $partid = empty($_GET['part']) ?
0 : $_GET['part'];
64 $banana->state
= Array ('group' => $group, 'artid' => $artid);
66 if (is_null($group)) {
68 if (isset($_GET['subscribe'])) {
69 return $banana->action_listSubs();
70 } elseif (isset($_POST['subscribe'])) {
71 $banana->action_saveSubs();
73 return $banana->action_listGroups();
75 } elseif (is_null($artid)) {
76 if (isset($_POST['action']) && $_POST['action'] == 'new') {
77 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
78 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
79 return $banana->action_newFup($group);
81 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
86 if (isset($_POST['action']) && $_POST['action']=='cancel') {
87 $res = $banana->action_cancelArticle($group, $artid);
92 if (isset($_GET['action'])) {
93 switch ($_GET['action']) {
95 $res .= $banana->action_showArticle($group, $artid, $partid);
96 if ($banana->post
->checkcancel()) {
97 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
98 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
99 . '<input type="hidden" name="action" value="cancel" />'
100 . '<input type="submit" value="Annuler !" />'
107 return $banana->action_newFup($group, $artid);
111 if (isset($_GET['pj'])) {
113 if (isset($_GET['action']) && $_GET['action'] == 'view') {
116 return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
119 return $res . $banana->action_showArticle($group, $artid, $partid);
123 /**************************************************************************/
125 /**************************************************************************/
127 function action_saveSubs()
132 function action_listGroups()
136 $cuts = displayshortcuts();
137 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
138 if (count($this->newgroups
->overview
)) {
139 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
140 $res .= $this->newgroups
->to_html();
147 function action_listSubs()
149 $this->_require('groups');
150 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
152 $cuts = displayshortcuts();
153 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
159 function action_showThread($group, $first)
161 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
163 if ($first > count($this->spool
->overview
)) {
164 $first = count($this->spool
->overview
);
167 $first = $first - ($first %
$this->tmax
) +
1;
169 $cuts = displayshortcuts($first);
171 $res = '<h1>'.$group.'</h1>'.$cuts;
172 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
179 function action_showArticle($group, $id, $part)
181 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
182 $this->_newPost($id);
184 if ($this->nntp
->lasterrorcode
== "423") {
185 $this->spool
->delid($id);
188 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
191 $cuts = displayshortcuts();
192 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
193 $res .= $this->post
->to_html($part);
200 function action_getAttachment($group, $id, $pjid, $action)
202 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
203 $this->_newPost($id);
205 if ($this->nntp
->lasterrorcode
== "423") {
206 $this->spool
->delid($id);
209 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
213 if ($this->post
->get_attachment($pjid, $action)) {
216 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
220 function action_cancelArticle($group, $id)
222 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
223 $this->_newPost($id);
224 $mid = array_search($id, $this->spool
->ids
);
226 if (!$this->post
->checkcancel()) {
227 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
229 $msg = 'From: '.$this->profile
['name']."\n"
230 . "Newsgroups: $group\n"
231 . "Subject: cmsg $mid\n"
233 . "Control: cancel $mid\n"
235 . "Message canceled with Banana";
236 if ($this->nntp
->post($msg)) {
237 $this->spool
->delid($id);
239 header("Location: ?group=$group&first=$id");
241 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
245 function action_newFup($group, $id = -1)
247 $subject = $body = '';
251 $this->nntp
->group($group);
252 $this->_newPost($id);
254 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
255 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->body
, "> ");
256 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
262 $cuts = displayshortcuts();
263 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
264 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
265 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
266 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
267 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
268 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
269 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
270 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
271 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
272 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
273 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
274 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></th>';
275 $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
276 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
277 $html .= '<input type="file" name="newpj" /></td></tr>';
278 $html .= '<tr><th colspan="2">';
280 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
282 $html .= '<input type="hidden" name="action" value="new" />';
283 $html .= '<input type="submit" /></th></tr>';
284 $html .= '</table></form>';
289 function action_doFup($group, $artid = -1)
291 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
292 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
294 foreach(array('subject', 'name', 'org', 'body') as $key) {
295 $_POST[$key] = utf8_encode($_POST[$key]);
299 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
300 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
301 $msg = 'From: '.$this->profile
['name']."\n"
302 . "Newsgroups: ".$_POST['newsgroups']."\n"
303 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
304 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
305 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
308 $this->_require('post');
309 $post = new BananaPost($artid);
310 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
311 $msg .= "References: $refs{$post->headers['message-id']}\n";
314 $body = wrap($body, "", $this->wrap
);
316 // include attachment in the body
317 $uploaded = $this->_upload('newpj');
318 if ($uploaded['error'] == 0) {
319 $this->custom
= $this->custom_mp
;
320 $body = "\n--".$this->boundary
."\n".$this->custom_bd
."\n\n".$body."\n--".$this->boundary
."\n";
322 $body .= 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n";
323 $body .= 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
324 $body .= 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n\n";
325 $body .= $uploaded['data'];
326 $body .= '--'.$this->boundary
.'--';
328 #TODO:afficher les erreurs lorsque l'upload ne marche pas
330 // finalise and post the message
331 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
333 if ($this->nntp
->post($msg)) {
334 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
336 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
340 /**************************************************************************/
341 /* Private functions */
342 /**************************************************************************/
344 function _newSpool($group, $disp=0, $since='') {
345 $this->_require('spool');
346 if (!$this->spool ||
$this->spool
->group
!= $group) {
347 $this->spool
= new BananaSpool($group, $disp, $since);
351 function _newPost($id)
353 $this->_require('post');
354 $this->post
= new BananaPost($id);
359 $this->_require('groups');
360 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
361 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
362 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
366 function _require($file)
368 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
371 function _upload($file)
373 if ($_FILES[$file]['name'] == "") {
374 return Array( 'error' => -1 );
378 $_FILES[$file]['tmp_name'];
380 // test if upload is ok
381 $file = $_FILES[$file];
382 if ($file['size'] == 0 ||
$file['error'] != 0) {
383 if ($file['error'] == 0) {
389 // adding custum data
390 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
392 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
396 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
397 if ($encod == 'base64') {
398 $data = chunk_split(base64_encode($data));
400 $file['name'] = basename($file['name']);
401 $file['type'] = $mime;
402 $file['encoding'] = $encod;
403 $file['data'] = $data;