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 $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
28 var $host = 'news://localhost:119/';
30 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
31 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
33 var $state = Array('group' => null
, 'artid' => null
);
42 $this->_require('NetNNTP');
43 setlocale(LC_ALL
, $this->profile
['locale']);
44 $this->nntp
= new nntp($this->host
);
47 function run($class = 'Banana')
50 Banana
::_require('misc');
51 $banana = new $class();
54 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
57 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
58 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
59 $partid = empty($_GET['part']) ?
0 : $_GET['part'];
60 $banana->state
= Array ('group' => $group, 'artid' => $artid);
62 if (is_null($group)) {
64 if (isset($_GET['subscribe'])) {
65 return $banana->action_listSubs();
66 } elseif (isset($_POST['subscribe'])) {
67 $banana->action_saveSubs();
69 return $banana->action_listGroups();
71 } elseif (is_null($artid)) {
73 if (isset($_POST['action']) && $_POST['action'] == 'new') {
74 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
75 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
76 return $banana->action_newFup($group);
78 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
83 if (isset($_POST['action']) && $_POST['action']=='cancel') {
84 $res = $banana->action_cancelArticle($group, $artid);
89 if (isset($_GET['action'])) {
90 switch ($_GET['action']) {
92 $res .= $banana->action_showArticle($group, $artid, $partid);
93 if ($banana->post
->checkcancel()) {
94 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
95 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
96 . '<input type="hidden" name="action" value="cancel" />'
97 . '<input type="submit" value="Annuler !" />'
104 return $banana->action_newFup($group, $artid);
108 if (isset($_GET['pj'])) {
110 if (isset($_GET['action']) && $_GET['action'] == 'view') {
113 return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
116 return $res . $banana->action_showArticle($group, $artid, $partid);
120 /**************************************************************************/
122 /**************************************************************************/
124 function action_saveSubs()
129 function action_listGroups()
133 $cuts = displayshortcuts();
134 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
135 if (count($this->newgroups
->overview
)) {
136 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
137 $res .= $this->newgroups
->to_html();
144 function action_listSubs()
146 $this->_require('groups');
147 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
149 $cuts = displayshortcuts();
150 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
156 function action_showThread($group, $first)
158 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
160 if ($first > count($this->spool
->overview
)) {
161 $first = count($this->spool
->overview
);
164 $first = $first - ($first %
$this->tmax
) +
1;
166 $cuts = displayshortcuts($first);
168 $res = '<h1>'.$group.'</h1>'.$cuts;
169 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
176 function action_showArticle($group, $id, $part)
178 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
179 $this->_newPost($id);
181 if ($this->nntp
->lasterrorcode
== "423") {
182 $this->spool
->delid($id);
185 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
188 $cuts = displayshortcuts();
189 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
190 $res .= $this->post
->to_html($part);
197 function action_getAttachment($group, $id, $pjid, $action)
199 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
200 $this->_newPost($id);
202 if ($this->nntp
->lasterrorcode
== "423") {
203 $this->spool
->delid($id);
206 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
210 if ($this->post
->get_attachment($pjid, $action)) {
213 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
217 function action_cancelArticle($group, $id)
219 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
220 $this->_newPost($id);
221 $mid = array_search($id, $this->spool
->ids
);
223 if (!$this->post
->checkcancel()) {
224 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
226 $msg = 'From: '.$this->profile
['name']."\n"
227 . "Newsgroups: $group\n"
228 . "Subject: cmsg $mid\n"
230 . "Control: cancel $mid\n"
232 . "Message canceled with Banana";
233 if ($this->nntp
->post($msg)) {
234 $this->spool
->delid($id);
236 header("Location: ?group=$group&first=$id");
238 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
242 function action_newFup($group, $id = -1)
244 $subject = $body = '';
248 $this->nntp
->group($group);
249 $this->_newPost($id);
251 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
252 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->body
, "> ");
253 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
259 $cuts = displayshortcuts();
260 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
261 $html .= '<form action="?group='.$group.'" method="post" accept-charset="utf-8">';
262 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
263 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
264 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
265 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
266 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
267 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
268 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
269 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
270 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
271 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></th>';
272 $html .= '<tr><td colspan="2">';
274 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
276 $html .= '<input type="hidden" name="action" value="new" />';
277 $html .= '<input type="submit" /></td></tr>';
278 $html .= '</table></form>';
283 function action_doFup($group, $artid = -1)
285 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
286 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
288 foreach(array('subject', 'name', 'org', 'body') as $key) {
289 $_POST[$key] = utf8_encode($_POST[$key]);
293 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
294 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
295 $msg = 'From: '.$this->profile
['name']."\n"
296 . "Newsgroups: ".$_POST['newsgroups']."\n"
297 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
298 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
299 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
302 $this->_require('post');
303 $post = new BananaPost($artid);
304 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
305 $msg .= "References: $refs{$post->headers['message-id']}\n";
308 $msg .= $this->custom
.$this->profile
['customhdr']."\n".wrap($body, "", $this->wrap
);
310 if ($this->nntp
->post($msg)) {
311 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
313 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
317 /**************************************************************************/
318 /* Private functions */
319 /**************************************************************************/
321 function _newSpool($group, $disp=0, $since='') {
322 $this->_require('spool');
323 if (!$this->spool ||
$this->spool
->group
!= $group) {
324 $this->spool
= new BananaSpool($group, $disp, $since);
328 function _newPost($id)
330 $this->_require('post');
331 $this->post
= new BananaPost($id);
336 $this->_require('groups');
337 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
338 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
339 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
343 function _require($file)
345 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');