bfaa934d1b1a0d6e93a2192cb68d9d2da47ed6d9
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-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);
106 return $res . $banana->action_showArticle($group, $artid);
110 /**************************************************************************/
112 /**************************************************************************/
114 function action_saveSubs()
119 function action_listGroups()
123 $cuts = displayshortcuts();
124 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
125 if (count($this->newgroups
->overview
)) {
126 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
127 $res .= $this->newgroups
->to_html();
134 function action_listSubs()
136 $this->_require('groups');
137 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
139 $cuts = displayshortcuts();
140 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
146 function action_showThread($group, $first)
148 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
150 if ($first > count($this->spool
->overview
)) {
151 $first = count($this->spool
->overview
);
154 $first = $first - ($first %
$this->tmax
) +
1;
156 $cuts = displayshortcuts($first);
158 $res = '<h1>'.$group.'</h1>'.$cuts;
159 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
166 function action_showArticle($group, $id)
168 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
169 $this->_newPost($id);
171 if ($this->nntp
->lasterrorcode
== "423") {
172 $this->spool
->delid($id);
175 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
178 $cuts = displayshortcuts();
179 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
180 $res .= $this->post
->to_html();
187 function action_cancelArticle($group, $id)
189 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
190 $this->_newPost($id);
191 $mid = array_search($id, $this->spool
->ids
);
193 if (!$this->post
->checkcancel()) {
194 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
196 $msg = 'From: '.$this->profile
['name']."\n"
197 . "Newsgroups: $group\n"
198 . "Subject: cmsg $mid\n"
200 . "Control: cancel $mid\n"
202 . "Message canceled with Banana";
203 if ($this->nntp
->post($msg)) {
204 $this->spool
->delid($id);
206 header("Location: ?group=$group&first=$id");
208 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
212 function action_newFup($group, $id = -1)
214 $subject = $body = '';
218 $this->nntp
->group($group);
219 $this->_newPost($id);
221 $subject = preg_replace("/^re\s*:\s*/i", 'Re: ', $this->post
->headers
['subject']);
222 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->body
, "> ");
223 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
229 $cuts = displayshortcuts();
230 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
231 $html .= '<form action="?group='.$group.'" method="post" accept-charset="utf-8">';
232 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
233 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
234 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
235 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
236 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
237 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
238 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
239 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
240 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
241 .to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></th>';
242 $html .= '<tr><td colspan="2">';
244 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
246 $html .= '<input type="hidden" name="action" value="new" />';
247 $html .= '<input type="submit" /></td></tr>';
248 $html .= '</table></form>';
253 function action_doFup($group, $artid = -1)
255 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
256 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
257 $msg = 'From: '.$this->profile
['name']."\n"
258 . "Newsgroups: ".$_POST['newsgroups']."\n"
259 . "Subject: ".$_POST['subject']."\n"
260 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
261 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
264 $this->_require('post');
265 $post = new BananaPost($artid);
266 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
267 $msg .= "References: $refs{$post->headers['message-id']}\n";
270 $msg .= $this->custom
.$this->profile
['customhdr']."\n".wrap($body, "", $this->wrap
);
272 if ($this->nntp
->post($msg)) {
273 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
275 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
279 /**************************************************************************/
280 /* Private functions */
281 /**************************************************************************/
283 function _newSpool($group, $disp=0, $since='') {
284 $this->_require('spool');
285 if (!$this->spool ||
$this->spool
->group
!= $group) {
286 $this->spool
= new BananaSpool($group, $disp, $since);
290 function _newPost($id)
292 $this->_require('post');
293 $this->post
= new BananaPost($id);
298 $this->_require('groups');
299 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
300 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
301 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
305 function _require($file)
307 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');