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 $banana->state
= Array ('group' => $group, 'artid' => $artid);
61 if (is_null($group)) {
63 if (isset($_GET['subscribe'])) {
64 return $banana->action_listSubs();
65 } elseif (isset($_POST['subscribe'])) {
66 $banana->action_saveSubs();
68 return $banana->action_listGroups();
70 } elseif (is_null($artid)) {
72 if (isset($_POST['action']) && $_POST['action'] == 'new') {
73 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
74 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
75 return $banana->action_newFup($group);
77 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
82 if (isset($_POST['action']) && $_POST['action']=='cancel') {
83 $res = $banana->action_cancelArticle($group, $artid);
88 if (isset($_GET['action'])) {
89 switch ($_GET['action']) {
91 $res .= $banana->action_showArticle($group, $artid);
92 if ($banana->post
->checkcancel()) {
93 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
94 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
95 . '<input type="hidden" name="action" value="cancel" />'
96 . '<input type="submit" value="Annuler !" />'
103 return $banana->action_newFup($group, $artid);
107 if (isset($_GET['pj'])) {
109 if (isset($_GET['action']) && $_GET['action'] == 'view') {
112 return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
115 return $res . $banana->action_showArticle($group, $artid);
119 /**************************************************************************/
121 /**************************************************************************/
123 function action_saveSubs()
128 function action_listGroups()
132 $cuts = displayshortcuts();
133 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
134 if (count($this->newgroups
->overview
)) {
135 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
136 $res .= $this->newgroups
->to_html();
143 function action_listSubs()
145 $this->_require('groups');
146 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
148 $cuts = displayshortcuts();
149 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
155 function action_showThread($group, $first)
157 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
159 if ($first > count($this->spool
->overview
)) {
160 $first = count($this->spool
->overview
);
163 $first = $first - ($first %
$this->tmax
) +
1;
165 $cuts = displayshortcuts($first);
167 $res = '<h1>'.$group.'</h1>'.$cuts;
168 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
175 function action_showArticle($group, $id)
177 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
178 $this->_newPost($id);
180 if ($this->nntp
->lasterrorcode
== "423") {
181 $this->spool
->delid($id);
184 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
187 $cuts = displayshortcuts();
188 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
189 $res .= $this->post
->to_html();
196 function action_getAttachment($group, $id, $pjid, $action)
198 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
199 $this->_newPost($id);
201 if ($this->nntp
->lasterrorcode
== "423") {
202 $this->spool
->delid($id);
205 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
209 if ($this->post
->get_attachment($pjid, $action)) {
212 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
216 function action_cancelArticle($group, $id)
218 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
219 $this->_newPost($id);
220 $mid = array_search($id, $this->spool
->ids
);
222 if (!$this->post
->checkcancel()) {
223 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
225 $msg = 'From: '.$this->profile
['name']."\n"
226 . "Newsgroups: $group\n"
227 . "Subject: cmsg $mid\n"
229 . "Control: cancel $mid\n"
231 . "Message canceled with Banana";
232 if ($this->nntp
->post($msg)) {
233 $this->spool
->delid($id);
235 header("Location: ?group=$group&first=$id");
237 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
241 function action_newFup($group, $id = -1)
243 $subject = $body = '';
247 $this->nntp
->group($group);
248 $this->_newPost($id);
250 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
251 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->body
, "> ");
252 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
258 $cuts = displayshortcuts();
259 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
260 $html .= '<form action="?group='.$group.'" method="post" accept-charset="utf-8">';
261 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
262 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
263 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
264 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
265 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
266 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
267 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
268 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
269 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
270 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></th>';
271 $html .= '<tr><td colspan="2">';
273 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
275 $html .= '<input type="hidden" name="action" value="new" />';
276 $html .= '<input type="submit" /></td></tr>';
277 $html .= '</table></form>';
282 function action_doFup($group, $artid = -1)
284 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
285 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
287 foreach(array('subject', 'name', 'org', 'body') as $key) {
288 $_POST[$key] = utf8_encode($_POST[$key]);
292 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
293 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
294 $msg = 'From: '.$this->profile
['name']."\n"
295 . "Newsgroups: ".$_POST['newsgroups']."\n"
296 . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
297 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
298 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
301 $this->_require('post');
302 $post = new BananaPost($artid);
303 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
304 $msg .= "References: $refs{$post->headers['message-id']}\n";
307 $msg .= $this->custom
.$this->profile
['customhdr']."\n".wrap($body, "", $this->wrap
);
309 if ($this->nntp
->post($msg)) {
310 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
312 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
316 /**************************************************************************/
317 /* Private functions */
318 /**************************************************************************/
320 function _newSpool($group, $disp=0, $since='') {
321 $this->_require('spool');
322 if (!$this->spool ||
$this->spool
->group
!= $group) {
323 $this->spool
= new BananaSpool($group, $disp, $since);
327 function _newPost($id)
329 $this->_require('post');
330 $this->post
= new BananaPost($id);
335 $this->_require('groups');
336 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
337 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
338 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
342 function _require($file)
344 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');