7aa348cb695fdd619009e61b933c46bcec7e99c9
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');
26 var $boundary = "bananaBoundary42";
27 var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
28 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\nUser-Agent: Banana @VERSION@\n";
29 var $custom_bd = "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit";
31 var $host = 'news://localhost:119/';
33 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
34 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
36 var $state = Array('group' => null
, 'artid' => null
);
45 $this->_require('NetNNTP');
46 setlocale(LC_ALL
, $this->profile
['locale']);
47 $this->nntp
= new nntp($this->host
);
50 function run($class = 'Banana')
53 Banana
::_require('misc');
54 $banana = new $class();
57 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
60 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
61 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
62 $partid = empty($_GET['part']) ?
0 : $_GET['part'];
63 $banana->state
= Array ('group' => $group, 'artid' => $artid);
65 if (is_null($group)) {
67 if (isset($_GET['subscribe'])) {
68 return $banana->action_listSubs();
69 } elseif (isset($_POST['subscribe'])) {
70 $banana->action_saveSubs();
72 return $banana->action_listGroups();
74 } elseif (is_null($artid)) {
75 if (isset($_POST['action']) && $_POST['action'] == 'new') {
76 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
77 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
78 return $banana->action_newFup($group);
80 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
85 if (isset($_POST['action']) && $_POST['action']=='cancel') {
86 $res = $banana->action_cancelArticle($group, $artid);
91 if (isset($_GET['action'])) {
92 switch ($_GET['action']) {
94 $res .= $banana->action_showArticle($group, $artid, $partid);
95 if ($banana->post
->checkcancel()) {
96 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
97 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
98 . '<input type="hidden" name="action" value="cancel" />'
99 . '<input type="submit" value="Annuler !" />'
106 return $banana->action_newFup($group, $artid);
110 if (isset($_GET['pj'])) {
112 if (isset($_GET['action']) && $_GET['action'] == 'view') {
115 return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
118 return $res . $banana->action_showArticle($group, $artid, $partid);
122 /**************************************************************************/
124 /**************************************************************************/
126 function action_saveSubs()
131 function action_listGroups()
135 $cuts = displayshortcuts();
136 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
137 if (count($this->newgroups
->overview
)) {
138 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
139 $res .= $this->newgroups
->to_html();
146 function action_listSubs()
148 $this->_require('groups');
149 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
151 $cuts = displayshortcuts();
152 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
158 function action_showThread($group, $first)
160 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
162 if ($first > count($this->spool
->overview
)) {
163 $first = count($this->spool
->overview
);
166 $first = $first - ($first %
$this->tmax
) +
1;
168 $cuts = displayshortcuts($first);
170 $res = '<h1>'.$group.'</h1>'.$cuts;
171 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
178 function action_showArticle($group, $id, $part)
180 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
181 $this->_newPost($id);
183 if ($this->nntp
->lasterrorcode
== "423") {
184 $this->spool
->delid($id);
187 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
190 $cuts = displayshortcuts();
191 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
192 $res .= $this->post
->to_html($part);
199 function action_getAttachment($group, $id, $pjid, $action)
201 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
202 $this->_newPost($id);
204 if ($this->nntp
->lasterrorcode
== "423") {
205 $this->spool
->delid($id);
208 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
212 if ($this->post
->get_attachment($pjid, $action)) {
215 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
219 function action_cancelArticle($group, $id)
221 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
222 $this->_newPost($id);
223 $mid = array_search($id, $this->spool
->ids
);
225 if (!$this->post
->checkcancel()) {
226 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
228 $msg = 'From: '.$this->profile
['name']."\n"
229 . "Newsgroups: $group\n"
230 . "Subject: cmsg $mid\n"
232 . "Control: cancel $mid\n"
234 . "Message canceled with Banana";
235 if ($this->nntp
->post($msg)) {
236 $this->spool
->delid($id);
238 header("Location: ?group=$group&first=$id");
240 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
244 function action_newFup($group, $id = -1)
246 $subject = $body = '';
250 $this->nntp
->group($group);
251 $this->_newPost($id);
253 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
254 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->body
, "> ");
255 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
261 $cuts = displayshortcuts();
262 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
263 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
264 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
265 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
266 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
267 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
268 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
269 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
270 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
271 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
272 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
273 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></th>';
274 $html .= '<tr><th colspan="2">'._b_('Pièces jointes').'</th></tr>';
275 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="100000" />';
276 $html .= '<input type="file" name="newpj" /></td></tr>';
277 $html .= '<tr><th colspan="2">';
279 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
281 $html .= '<input type="hidden" name="action" value="new" />';
282 $html .= '<input type="submit" /></th></tr>';
283 $html .= '</table></form>';
288 function action_doFup($group, $artid = -1)
290 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
291 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
293 foreach(array('subject', 'name', 'org', 'body') as $key) {
294 $_POST[$key] = utf8_encode($_POST[$key]);
298 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
299 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
300 $msg = 'From: '.$this->profile
['name']."\n"
301 . "Newsgroups: ".$_POST['newsgroups']."\n"
302 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
303 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
304 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
307 $this->_require('post');
308 $post = new BananaPost($artid);
309 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
310 $msg .= "References: $refs{$post->headers['message-id']}\n";
313 $body = wrap($body, "", $this->wrap
);
315 // include attachment in the body
316 if (isset($_FILES['newpj'])) {
317 $this->custom
= $this->custom_mp
;
318 $body = "\n--".$this->boundary
."\n".$this->custom_bd
."\n\n".$body."\n--".$this->boundary
."\n";
319 $tmpname = $_FILES['newpj']['tmp_name'];
320 $file = basename($_FILES['newpj']['name']);
321 $mime = shell_exec("file -bi $tmpname"); //Because mime_content_type don't work :(
322 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
326 preg_match("@([^ ]+/[^ ]+)\r?\n@", $mime, $format);
331 $body .= 'Content-Type: '.$mime.'; name="'.$file."\"\n";
332 $body .= 'Content-Disposition: attachment; filename="'.$file."\"\n";
333 $body .= 'Content-Transfer-Encoding: '.$encod."\n\n";
334 if ($encod == 'base64') {
335 $body .= chunk_split(base64_encode(fread(fopen($tmpname, 'r'), filesize($tmpname))));
337 $body .= fread(fopen($tmpname, 'r'), filesize($tmpname));
339 $body .= '--'.$this->boundary
.'--';
342 // finalise and post the message
343 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
345 if ($this->nntp
->post($msg)) {
346 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
348 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
352 /**************************************************************************/
353 /* Private functions */
354 /**************************************************************************/
356 function _newSpool($group, $disp=0, $since='') {
357 $this->_require('spool');
358 if (!$this->spool ||
$this->spool
->group
!= $group) {
359 $this->spool
= new BananaSpool($group, $disp, $since);
363 function _newPost($id)
365 $this->_require('post');
366 $this->post
= new BananaPost($id);
371 $this->_require('groups');
372 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
373 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
374 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
378 function _require($file)
380 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');