Commit | Line | Data |
---|---|---|
abd0915a PHM |
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'); | |
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'); | |
18 | ||
19 | ||
20 | var $tbefore = 5; | |
21 | var $tafter = 5; | |
22 | var $tmax = 50; | |
23 | ||
24 | var $wrap = 74; | |
25 | ||
a75dcfa4 | 26 | var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n"; |
abd0915a PHM |
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']); | |
59 | $banana->state = Array ('group' => $group, 'artid' => $artid); | |
60 | ||
61 | if (is_null($group)) { | |
62 | ||
63 | if (isset($_GET['subscribe'])) { | |
64 | return $banana->action_listSubs(); | |
65 | } elseif (isset($_POST['subscribe'])) { | |
66 | $banana->action_saveSubs(); | |
67 | } | |
68 | return $banana->action_listGroups(); | |
69 | ||
70 | } elseif (is_null($artid)) { | |
71 | ||
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); | |
76 | } else { | |
77 | return $banana->action_showThread($group, isset($_GET['first']) ? intval($_GET['first']) : 1); | |
78 | } | |
79 | ||
80 | } else { | |
81 | ||
82 | if (isset($_POST['action']) && $_POST['action']=='cancel') { | |
83 | $res = $banana->action_cancelArticle($group, $artid); | |
84 | } else { | |
85 | $res = ''; | |
86 | } | |
87 | ||
88 | if (isset($_GET['action'])) { | |
89 | switch ($_GET['action']) { | |
90 | case 'cancel': | |
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 !" />' | |
97 | . '</p></form>'; | |
98 | return $form.$res; | |
99 | } | |
100 | return $res; | |
101 | ||
102 | case 'new': | |
103 | return $banana->action_newFup($group, $artid); | |
104 | } | |
105 | } | |
106 | return $res . $banana->action_showArticle($group, $artid); | |
107 | } | |
108 | } | |
109 | ||
110 | /**************************************************************************/ | |
111 | /* actions */ | |
112 | /**************************************************************************/ | |
113 | ||
114 | function action_saveSubs() | |
115 | { | |
116 | return; | |
117 | } | |
118 | ||
119 | function action_listGroups() | |
120 | { | |
121 | $this->_newGroup(); | |
122 | ||
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(); | |
128 | } | |
129 | ||
130 | $this->nntp->quit(); | |
131 | return $res.$cuts; | |
132 | } | |
133 | ||
134 | function action_listSubs() | |
135 | { | |
136 | $this->_require('groups'); | |
137 | $this->groups = new BananaGroups(BANANA_GROUP_ALL); | |
138 | ||
139 | $cuts = displayshortcuts(); | |
140 | $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups->to_html(true).$cuts; | |
141 | ||
142 | $this->nntp->quit(); | |
143 | return $res; | |
144 | } | |
145 | ||
146 | function action_showThread($group, $first) | |
147 | { | |
148 | $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); | |
149 | ||
150 | if ($first > count($this->spool->overview)) { | |
151 | $first = count($this->spool->overview); | |
152 | } | |
153 | ||
154 | $first = $first - ($first % $this->tmax) + 1; | |
155 | ||
156 | $cuts = displayshortcuts($first); | |
157 | ||
158 | $res = '<h1>'.$group.'</h1>'.$cuts; | |
159 | $res .= $this->spool->to_html($first, $first+$this->tmax); | |
160 | ||
161 | $this->nntp->quit(); | |
162 | ||
163 | return $res.$cuts; | |
164 | } | |
165 | ||
166 | function action_showArticle($group, $id) | |
167 | { | |
168 | $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); | |
169 | $this->_newPost($id); | |
170 | if (!$this->post) { | |
171 | if ($this->nntp->lasterrorcode == "423") { | |
172 | $this->spool->delid($id); | |
173 | } | |
174 | $this->nntp->quit(); | |
175 | return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>'; | |
176 | } | |
177 | ||
178 | $cuts = displayshortcuts(); | |
179 | $res = '<h1>'._b_('Message').'</h1>'.$cuts; | |
180 | $res .= $this->post->to_html(); | |
181 | ||
182 | $this->nntp->quit(); | |
183 | ||
184 | return $res.$cuts; | |
185 | } | |
186 | ||
187 | function action_cancelArticle($group, $id) | |
188 | { | |
189 | $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); | |
190 | $this->_newPost($id); | |
191 | $mid = array_search($id, $this->spool->ids); | |
192 | ||
193 | if (!$this->post->checkcancel()) { | |
194 | return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>'; | |
195 | } | |
196 | $msg = 'From: '.$this->profile['name']."\n" | |
197 | . "Newsgroups: $group\n" | |
198 | . "Subject: cmsg $mid\n" | |
199 | . $this->custom | |
200 | . "Control: cancel $mid\n" | |
201 | . "\n" | |
202 | . "Message canceled with Banana"; | |
203 | if ($this->nntp->post($msg)) { | |
204 | $this->spool->delid($id); | |
205 | $this->nntp->quit(); | |
206 | header("Location: ?group=$group&first=$id"); | |
207 | } else { | |
208 | return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>'; | |
209 | } | |
210 | } | |
211 | ||
212 | function action_newFup($group, $id = -1) | |
213 | { | |
214 | $subject = $body = ''; | |
215 | $target = $group; | |
216 | ||
217 | if ($id > 0) { | |
218 | $this->nntp->group($group); | |
219 | $this->_newPost($id); | |
220 | if ($this->post) { | |
221 | $subject = preg_replace("/^re\s*:\s*/i", 'Re: ', $this->post->headers['subject']); | |
222 | $body = $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']; | |
224 | } | |
225 | } | |
226 | ||
227 | $this->nntp->quit(); | |
228 | ||
229 | $cuts = displayshortcuts(); | |
230 | $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts; | |
987299b4 | 231 | $html .= '<form action="?group='.$group.'" method="post" accept-charset="utf-8">'; |
abd0915a PHM |
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>'; | |
402ffef8 | 238 | $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile['org'].'</td></tr>'; |
abd0915a PHM |
239 | $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>'; |
240 | $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">' | |
987299b4 | 241 | .to_entities($body).($this->profile['sig'] ? "\n\n-- \n".htmlentities($this->profile['sig']) : '').'</textarea></td></th>'; |
abd0915a PHM |
242 | $html .= '<tr><td colspan="2">'; |
243 | if ($id > 0) { | |
244 | $html .= '<input type="hidden" name="artid" value="'.$id.'" />'; | |
245 | } | |
246 | $html .= '<input type="hidden" name="action" value="new" />'; | |
247 | $html .= '<input type="submit" /></td></tr>'; | |
248 | $html .= '</table></form>'; | |
249 | ||
250 | return $html.$cuts; | |
251 | } | |
252 | ||
253 | function action_doFup($group, $artid = -1) | |
254 | { | |
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"); | |
262 | ||
263 | if ($artid != -1) { | |
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"; | |
268 | } | |
269 | ||
270 | $msg .= $this->custom.$this->profile['customhdr']."\n".wrap($body, "", $this->wrap); | |
271 | ||
272 | if ($this->nntp->post($msg)) { | |
273 | header("Location: ?group=$group".($artid==-1 ? '' : "&first=$artid")); | |
274 | } else { | |
275 | return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid); | |
276 | } | |
277 | } | |
278 | ||
279 | /**************************************************************************/ | |
280 | /* Private functions */ | |
281 | /**************************************************************************/ | |
282 | ||
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); | |
287 | } | |
288 | } | |
289 | ||
290 | function _newPost($id) | |
291 | { | |
292 | $this->_require('post'); | |
293 | $this->post = new BananaPost($id); | |
294 | } | |
295 | ||
296 | function _newGroup() | |
297 | { | |
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); | |
302 | } | |
303 | } | |
304 | ||
305 | function _require($file) | |
306 | { | |
307 | require_once (dirname(__FILE__).'/'.$file.'.inc.php'); | |
308 | } | |
309 | } | |
310 | ||
311 | ?> |