78cd27b3 |
1 | <?php |
2 | /******************************************************************************** |
3 | * install.d/config.inc.php : configuration file |
4 | * -------------------------- |
5 | * |
6 | * This file is part of the banana distribution |
7 | * Copyright: See COPYING files that comes with this distribution |
8 | ********************************************************************************/ |
9 | |
10 | class Banana |
11 | { |
12 | var $maxspool = 3000; |
13 | |
14 | var $hdecode = array('from','name','organization','subject'); |
7a0e2710 |
15 | var $parse_hdr = array('content-disposition', 'content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from', |
78cd27b3 |
16 | 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face'); |
17 | var $show_hdr = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face'); |
18 | |
19 | |
20 | var $tbefore = 5; |
21 | var $tafter = 5; |
22 | var $tmax = 50; |
23 | |
24 | var $wrap = 74; |
25 | |
26 | var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n"; |
27 | |
28 | var $host = 'news://localhost:119/'; |
29 | |
30 | var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '', |
31 | 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array()); |
32 | |
33 | var $state = Array('group' => null, 'artid' => null); |
34 | var $nntp; |
35 | var $groups; |
36 | var $newgroups; |
37 | var $post; |
38 | var $spool; |
39 | |
40 | function Banana() |
41 | { |
42 | $this->_require('NetNNTP'); |
43 | setlocale(LC_ALL, $this->profile['locale']); |
44 | $this->nntp = new nntp($this->host); |
45 | } |
46 | |
47 | function run($class = 'Banana') |
48 | { |
49 | global $banana; |
50 | Banana::_require('misc'); |
51 | $banana = new $class(); |
52 | |
53 | if (!$banana->nntp) { |
54 | return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>'; |
55 | } |
56 | |
57 | $group = empty($_GET['group']) ? null : strtolower($_GET['group']); |
58 | $artid = empty($_GET['artid']) ? null : strtolower($_GET['artid']); |
1f75b135 |
59 | $partid = empty($_GET['part']) ? 0 : $_GET['part']; |
78cd27b3 |
60 | $banana->state = Array ('group' => $group, 'artid' => $artid); |
61 | |
62 | if (is_null($group)) { |
63 | |
64 | if (isset($_GET['subscribe'])) { |
65 | return $banana->action_listSubs(); |
66 | } elseif (isset($_POST['subscribe'])) { |
67 | $banana->action_saveSubs(); |
68 | } |
69 | return $banana->action_listGroups(); |
70 | |
71 | } elseif (is_null($artid)) { |
72 | |
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); |
77 | } else { |
78 | return $banana->action_showThread($group, isset($_GET['first']) ? intval($_GET['first']) : 1); |
79 | } |
80 | |
81 | } else { |
82 | |
83 | if (isset($_POST['action']) && $_POST['action']=='cancel') { |
84 | $res = $banana->action_cancelArticle($group, $artid); |
85 | } else { |
86 | $res = ''; |
87 | } |
88 | |
89 | if (isset($_GET['action'])) { |
90 | switch ($_GET['action']) { |
91 | case 'cancel': |
1f75b135 |
92 | $res .= $banana->action_showArticle($group, $artid, $partid); |
78cd27b3 |
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 !" />' |
98 | . '</p></form>'; |
99 | return $form.$res; |
100 | } |
101 | return $res; |
102 | |
103 | case 'new': |
104 | return $banana->action_newFup($group, $artid); |
105 | } |
106 | } |
7a0e2710 |
107 | |
108 | if (isset($_GET['pj'])) { |
109 | $action = false; |
110 | if (isset($_GET['action']) && $_GET['action'] == 'view') { |
111 | $action = true; |
112 | } |
113 | return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action); |
114 | } |
115 | |
1f75b135 |
116 | return $res . $banana->action_showArticle($group, $artid, $partid); |
78cd27b3 |
117 | } |
118 | } |
119 | |
120 | /**************************************************************************/ |
121 | /* actions */ |
122 | /**************************************************************************/ |
123 | |
124 | function action_saveSubs() |
125 | { |
126 | return; |
127 | } |
128 | |
129 | function action_listGroups() |
130 | { |
131 | $this->_newGroup(); |
132 | |
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(); |
138 | } |
139 | |
140 | $this->nntp->quit(); |
141 | return $res.$cuts; |
142 | } |
143 | |
144 | function action_listSubs() |
145 | { |
146 | $this->_require('groups'); |
147 | $this->groups = new BananaGroups(BANANA_GROUP_ALL); |
148 | |
149 | $cuts = displayshortcuts(); |
150 | $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups->to_html(true).$cuts; |
151 | |
152 | $this->nntp->quit(); |
153 | return $res; |
154 | } |
155 | |
156 | function action_showThread($group, $first) |
157 | { |
158 | $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); |
159 | |
160 | if ($first > count($this->spool->overview)) { |
161 | $first = count($this->spool->overview); |
162 | } |
163 | |
164 | $first = $first - ($first % $this->tmax) + 1; |
165 | |
166 | $cuts = displayshortcuts($first); |
167 | |
168 | $res = '<h1>'.$group.'</h1>'.$cuts; |
169 | $res .= $this->spool->to_html($first, $first+$this->tmax); |
170 | |
171 | $this->nntp->quit(); |
172 | |
173 | return $res.$cuts; |
174 | } |
175 | |
1f75b135 |
176 | function action_showArticle($group, $id, $part) |
78cd27b3 |
177 | { |
178 | $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); |
179 | $this->_newPost($id); |
180 | if (!$this->post) { |
181 | if ($this->nntp->lasterrorcode == "423") { |
182 | $this->spool->delid($id); |
183 | } |
184 | $this->nntp->quit(); |
185 | return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>'; |
186 | } |
187 | |
188 | $cuts = displayshortcuts(); |
189 | $res = '<h1>'._b_('Message').'</h1>'.$cuts; |
1f75b135 |
190 | $res .= $this->post->to_html($part); |
78cd27b3 |
191 | |
192 | $this->nntp->quit(); |
193 | |
194 | return $res.$cuts; |
195 | } |
196 | |
7a0e2710 |
197 | function action_getAttachment($group, $id, $pjid, $action) |
198 | { |
199 | $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); |
200 | $this->_newPost($id); |
201 | if (!$this->post) { |
202 | if ($this->nntp->lasterrorcode == "423") { |
203 | $this->spool->delid($id); |
204 | } |
205 | $this->nntp->quit(); |
206 | return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>'; |
207 | } |
208 | |
209 | $this->nntp->quit(); |
210 | if ($this->post->get_attachment($pjid, $action)) { |
211 | return ""; |
212 | } else { |
213 | return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>'; |
214 | } |
215 | } |
216 | |
78cd27b3 |
217 | function action_cancelArticle($group, $id) |
218 | { |
219 | $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); |
220 | $this->_newPost($id); |
221 | $mid = array_search($id, $this->spool->ids); |
222 | |
223 | if (!$this->post->checkcancel()) { |
224 | return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>'; |
225 | } |
226 | $msg = 'From: '.$this->profile['name']."\n" |
227 | . "Newsgroups: $group\n" |
228 | . "Subject: cmsg $mid\n" |
229 | . $this->custom |
230 | . "Control: cancel $mid\n" |
231 | . "\n" |
232 | . "Message canceled with Banana"; |
233 | if ($this->nntp->post($msg)) { |
234 | $this->spool->delid($id); |
235 | $this->nntp->quit(); |
236 | header("Location: ?group=$group&first=$id"); |
237 | } else { |
238 | return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>'; |
239 | } |
240 | } |
241 | |
242 | function action_newFup($group, $id = -1) |
243 | { |
244 | $subject = $body = ''; |
245 | $target = $group; |
246 | |
247 | if ($id > 0) { |
248 | $this->nntp->group($group); |
249 | $this->_newPost($id); |
250 | if ($this->post) { |
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']; |
254 | } |
255 | } |
256 | |
257 | $this->nntp->quit(); |
258 | |
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">'; |
273 | if ($id > 0) { |
274 | $html .= '<input type="hidden" name="artid" value="'.$id.'" />'; |
275 | } |
276 | $html .= '<input type="hidden" name="action" value="new" />'; |
277 | $html .= '<input type="submit" /></td></tr>'; |
278 | $html .= '</table></form>'; |
279 | |
280 | return $html.$cuts; |
281 | } |
282 | |
283 | function action_doFup($group, $artid = -1) |
284 | { |
285 | if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name']) |
286 | && is_utf8($_POST['org']) && is_utf8($_POST['body']) ) |
287 | ) { |
288 | foreach(array('subject', 'name', 'org', 'body') as $key) { |
289 | $_POST[$key] = utf8_encode($_POST[$key]); |
290 | } |
291 | } |
292 | |
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"); |
300 | |
301 | if ($artid != -1) { |
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"; |
306 | } |
307 | |
308 | $msg .= $this->custom.$this->profile['customhdr']."\n".wrap($body, "", $this->wrap); |
309 | |
310 | if ($this->nntp->post($msg)) { |
311 | header("Location: ?group=$group".($artid==-1 ? '' : "&first=$artid")); |
312 | } else { |
313 | return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid); |
314 | } |
315 | } |
316 | |
317 | /**************************************************************************/ |
318 | /* Private functions */ |
319 | /**************************************************************************/ |
320 | |
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); |
325 | } |
326 | } |
327 | |
328 | function _newPost($id) |
329 | { |
330 | $this->_require('post'); |
331 | $this->post = new BananaPost($id); |
332 | } |
333 | |
334 | function _newGroup() |
335 | { |
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); |
340 | } |
341 | } |
342 | |
343 | function _require($file) |
344 | { |
345 | require_once (dirname(__FILE__).'/'.$file.'.inc.php'); |
346 | } |
347 | } |
348 | |
349 | ?> |