dead code + css
[banana.git] / include / banana.inc.php.in
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
26 var $custom = "Content-Type: text/plain; charset=iso-8859-15\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 require_once('include/NetNNTP.inc.php');
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 require_once("include/misc.inc.php");
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 return $banana->action_listGroups();
64
65 } elseif (is_null($artid)) {
66
67 if (isset($_POST['action']) && $_POST['action'] == 'new') {
68 return $banana->action_doFup($group, isset($_POST['artid']) ? intval($_POST['artid']) : -1);
69 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
70 return $banana->action_newFup($group);
71 } else {
72 return $banana->action_showThread($group, isset($_GET['first']) ? intval($_GET['first']) : 1);
73 }
74
75 } else {
76
77 if (isset($_POST['action']) && $_POST['action']=='cancel') {
78 $res = $banana->action_cancelArticle($group, $artid);
79 } else {
80 $res = '';
81 }
82
83 if (isset($_GET['action'])) {
84 switch ($_GET['action']) {
85 case 'cancel':
86 $res .= $banana->action_showArticle($group, $artid);
87 if ($banana->post->checkcancel()) {
88 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
89 . "<form action=\"?group=$group&amp;artid=$artid\" method='post'><p>"
90 . '<input type="hidden" name="action" value="cancel" />'
91 . '<input type="submit" value="Annuler !" />'
92 . '</p></form>';
93 return $form.$res;
94 }
95 return $res;
96
97 case 'new':
98 return $banana->action_newFup($group, $artid);
99 }
100 }
101 return $res . $banana->action_showArticle($group, $artid);
102 }
103 }
104
105 /**************************************************************************/
106 /* actions */
107 /**************************************************************************/
108
109 function action_listGroups()
110 {
111 $this->_newGroup();
112
113 $cuts = displayshortcuts();
114 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups->to_html();
115 if (count($this->newgroups->overview)) {
116 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
117 $res .= $this->newgroups->to_html();
118 }
119
120 $this->nntp->quit();
121 return $res.$cuts;
122 }
123
124 function action_listSubs()
125 {
126 require_once("include/groups.inc.php");
127 $this->groups = new BananaGroups(BANANA_GROUP_ALL);
128
129 $cuts = displayshortcuts();
130 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups->to_html(true).$cuts;
131
132 $this->nntp->quit();
133 return $res;
134 }
135
136 function action_showThread($group, $first)
137 {
138 $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
139
140 if ($first > count($this->spool->overview)) {
141 $first = count($this->spool->overview);
142 }
143
144 $first = $first - ($first % $this->tmax) + 1;
145
146 $cuts = displayshortcuts($first);
147
148 $res = '<h1>'.$group.'</h1>'.$cuts;
149 $res .= $this->spool->to_html($first, $first+$this->tmax);
150
151 $this->nntp->quit();
152
153 return $res.$cuts;
154 }
155
156 function action_showArticle($group, $id)
157 {
158 $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
159 $this->_newPost($id);
160 if (!$this->post) {
161 if ($this->nntp->lasterrorcode == "423") {
162 $this->spool->delid($id);
163 }
164 $this->nntp->quit();
165 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
166 }
167
168 $cuts = displayshortcuts();
169 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
170 $res .= $this->post->to_html();
171
172 $this->nntp->quit();
173
174 return $res.$cuts;
175 }
176
177 function action_cancelArticle($group, $id)
178 {
179 $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
180 $this->_newPost($id);
181 $mid = array_search($id, $this->spool->ids);
182
183 if (!$this->post->checkcancel()) {
184 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
185 }
186 $msg = 'From: '.$this->profile['name']."\n"
187 . "Newsgroups: $group\n"
188 . "Subject: cmsg $mid\n"
189 . $this->custom
190 . "Control: cancel $mid\n"
191 . "\n"
192 . "Message canceled with Banana";
193 if ($this->nntp->post($msg)) {
194 $this->spool->delid($id);
195 $this->nntp->quit();
196 header("Location: ?group=$group&amp;first=$id");
197 } else {
198 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
199 }
200 }
201
202 function action_newFup($group, $id = -1)
203 {
204 $subject = $body = '';
205 $target = $group;
206
207 if ($id > 0) {
208 $this->nntp->group($group);
209 $this->_newPost($id);
210 if ($this->post) {
211 $subject = preg_replace("/^re\s*:\s*/i", 'Re: ', $this->post->headers['subject']);
212 $body = $this->post->name." "._b_("a écrit")." :\n".wrap($this->post->body, "> ");
213 $target = isset($this->post->headers['followup-to']) ? $this->post->headers['followup-to'] : $this->post->headers['newsgroups'];
214 }
215 }
216
217 $this->nntp->quit();
218
219 $cuts = displayshortcuts();
220 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
221 $html .= '<form action="?group='.$group.'" method="post">';
222 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
223 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
224 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile['name']).'</td></tr>';
225 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
226 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
227 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
228 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile['org'].'</td></tr>';
229 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
230 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
231 .htmlentities($body).($this->profile['sig'] ? "\n\n-- \n".htmlentities($this->profile['sig']) : '').'</textarea></td></th>';
232 $html .= '<tr><td colspan="2">';
233 if ($id > 0) {
234 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
235 }
236 $html .= '<input type="hidden" name="action" value="new" />';
237 $html .= '<input type="submit" /></td></tr>';
238 $html .= '</table></form>';
239
240 return $html.$cuts;
241 }
242
243 function action_doFup($group, $artid = -1)
244 {
245 $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
246 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
247 $msg = 'From: '.$this->profile['name']."\n"
248 . "Newsgroups: ".$_POST['newsgroups']."\n"
249 . "Subject: ".$_POST['subject']."\n"
250 . (empty($this->profile['org']) ? '' : "Organization: {$this->profile['org']}\n")
251 . (empty($_POST['followup']) ? '' : 'Followup-To: '.$_POST['followup']."\n");
252
253 if ($artid != -1) {
254 require_once("include/post.inc.php");
255 $post = new BananaPost($artid);
256 $refs = ( isset($post->headers['references']) ? $post->headers['references']." " : "" );
257 $msg .= "References: $refs{$post->headers['message-id']}\n";
258 }
259
260 $msg .= $this->custom.$this->profile['customhdr']."\n".wrap($body, "", $this->wrap);
261
262 if ($this->nntp->post($msg)) {
263 header("Location: ?group=$group".($artid==-1 ? '' : "&first=$artid"));
264 } else {
265 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
266 }
267 }
268
269 /**************************************************************************/
270 /* Private functions */
271 /**************************************************************************/
272
273 function _newSpool($group, $disp=0, $since='') {
274 require_once('include/spool.inc.php');
275 if (!$this->spool || $this->spool->group != $group) {
276 $this->spool = new BananaSpool($group, $disp, $since);
277 }
278 }
279
280 function _newPost($id)
281 {
282 require_once("include/post.inc.php");
283 $this->post = new BananaPost($id);
284 }
285
286 function _newGroup()
287 {
288 require_once("include/groups.inc.php");
289 $this->groups = new BananaGroups(BANANA_GROUP_SUB);
290 if ($this->groups->type == BANANA_GROUP_SUB) {
291 $this->newgroups = new BananaGroups(BANANA_GROUP_NEW);
292 }
293 }
294 }
295
296 ?>