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 | { |
d28aa62d |
12 | var $maxspool = 3000; |
78cd27b3 |
13 | |
d28aa62d |
14 | var $hdecode = array('from','name','organization','subject'); |
28ab52c0 |
15 | var $parse_hdr = array('content-disposition', 'content-transfer-encoding', |
16 | 'content-type', 'content-id', 'date', 'followup-to', |
17 | 'from', 'message-id', 'newsgroups', 'organization', |
18 | 'references', 'subject', 'x-face'); |
19 | var $show_hdr = array('from', 'newsgroups', 'followup', 'date', |
20 | 'organization', 'references', 'x-face'); |
78cd27b3 |
21 | |
cc43419f |
22 | /** Favorites MIMEtypes to use, by order for reading multipart messages |
23 | */ |
24 | var $body_mime = array('text/plain', 'text/html', 'text/richtext'); |
a1937df3 |
25 | /** Indicate wether posting attachment is allowed |
26 | */ |
27 | var $can_attach = true; |
28 | /** Maximum allowed file size for attachment |
29 | */ |
ca3b1040 |
30 | var $maxfilesize = 100000; |
31 | /** Indicate wether x-face should be skinned as specials data or not |
32 | */ |
33 | var $formatxface = true; |
78cd27b3 |
34 | |
4f6a209a |
35 | /** Regexp for selecting newsgroups to show (if empty, match all newsgroups) |
36 | * ex : '^xorg\..*' for xorg.* |
37 | */ |
38 | var $grp_pattern; |
39 | |
d28aa62d |
40 | var $tbefore = 5; |
41 | var $tafter = 5; |
42 | var $tmax = 50; |
78cd27b3 |
43 | |
d28aa62d |
44 | var $wrap = 74; |
87514711 |
45 | /** Match an url |
46 | * Should be included in a regexp delimited using ! (eg: "!$url_regexp!i") |
47 | * If it matches, return 3 main parts : |
48 | * \\1 and \\3 are delimiters |
49 | * \\2 is the url |
50 | * |
51 | * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches); |
52 | * $matches[1] = "[" |
53 | * $matches[2] = "http://www.polytechnique.org" |
54 | * $matches[3] = "]" |
55 | */ |
e7241984 |
56 | var $url_regexp = '(["\[])?((?:https?|ftp|news)://(?:&|,?[a-z@0-9.~%$£µ&i#\-+=_/\?])*)(["\]])?'; |
78cd27b3 |
57 | |
87514711 |
58 | |
a1937df3 |
59 | /** Boundary for multipart messages |
60 | */ |
f12fdb59 |
61 | var $boundary = 'bananaBoundary42'; |
62 | /** Global headers to use for messages |
a1937df3 |
63 | */ |
f12fdb59 |
64 | var $custom = "Mime-Version: 1.0\nUser-Agent: Banana @VERSION@\n"; |
a1937df3 |
65 | /** Global headers to use from multipart messages |
66 | */ |
f12fdb59 |
67 | var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\n"; |
68 | /** Body type when using plain text |
a1937df3 |
69 | */ |
f12fdb59 |
70 | var $custom_plain= "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit\n"; |
78cd27b3 |
71 | |
a1937df3 |
72 | /** News serveur to use |
73 | */ |
d28aa62d |
74 | var $host = 'news://localhost:119/'; |
78cd27b3 |
75 | |
a1937df3 |
76 | /** User profile |
77 | */ |
d28aa62d |
78 | var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '', |
78cd27b3 |
79 | 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array()); |
80 | |
1254696c |
81 | var $state = Array('group' => null, 'artid' => null, 'action' => null); |
78cd27b3 |
82 | var $nntp; |
83 | var $groups; |
84 | var $newgroups; |
85 | var $post; |
86 | var $spool; |
87 | |
f6df9eb2 |
88 | var $get; |
1786dc36 |
89 | |
78cd27b3 |
90 | function Banana() |
91 | { |
92 | $this->_require('NetNNTP'); |
93 | setlocale(LC_ALL, $this->profile['locale']); |
94 | $this->nntp = new nntp($this->host); |
856dc84a |
95 | if (!$this->nntp || !$this->nntp->valid) { |
96 | $this->nntp = null; |
97 | } |
78cd27b3 |
98 | } |
99 | |
f6df9eb2 |
100 | /** Run Banana |
101 | * @param STRING class Name of the class to use |
102 | * @param ARRAY myget If defined is used instead of get |
103 | */ |
1786dc36 |
104 | function run($class = 'Banana', $myget = null) |
78cd27b3 |
105 | { |
106 | global $banana; |
aef14768 |
107 | |
78cd27b3 |
108 | Banana::_require('misc'); |
109 | $banana = new $class(); |
110 | |
1786dc36 |
111 | if (is_null($myget)) { |
112 | $banana->get = $_GET; |
113 | } else { |
114 | $banana->get = $myget; |
115 | } |
116 | |
78cd27b3 |
117 | if (!$banana->nntp) { |
118 | return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>'; |
119 | } |
120 | |
f37bac43 |
121 | $group = empty($banana->get['group']) ? null : $banana->get['group']; |
b2f7dc0b |
122 | if (!is_null($group) |
123 | && isset($banana->grp_pattern) && !preg_match('/' . $banana->grp_pattern . '/', $group)) { |
3c3d29bb |
124 | return '<p class="error">' |
125 | . $group . _b_(' : ce newsgroup n\'existe pas ou vous n\'avez pas l\'autorisation d\'y accéder') |
126 | . '</p>'; |
127 | } |
1786dc36 |
128 | $artid = empty($banana->get['artid']) ? null : strtolower($banana->get['artid']); |
129 | $partid = !isset($banana->get['part']) ? -1 : $banana->get['part']; |
1254696c |
130 | $action = !isset($banana->get['action']) ? null : $banana->get['action']; |
131 | $banana->state = Array ('group' => $group, 'artid' => $artid, 'action' => $action); |
78cd27b3 |
132 | |
133 | if (is_null($group)) { |
1786dc36 |
134 | if (isset($banana->get['subscribe'])) { |
78cd27b3 |
135 | return $banana->action_listSubs(); |
20e25a42 |
136 | } elseif (isset($_POST['validsubs'])) { |
78cd27b3 |
137 | $banana->action_saveSubs(); |
138 | } |
139 | return $banana->action_listGroups(); |
140 | |
141 | } elseif (is_null($artid)) { |
78cd27b3 |
142 | if (isset($_POST['action']) && $_POST['action'] == 'new') { |
143 | return $banana->action_doFup($group, isset($_POST['artid']) ? intval($_POST['artid']) : -1); |
1254696c |
144 | } elseif ($action == 'new') { |
78cd27b3 |
145 | return $banana->action_newFup($group); |
146 | } else { |
1786dc36 |
147 | return $banana->action_showThread($group, isset($banana->get['first']) ? intval($banana->get['first']) : 1); |
78cd27b3 |
148 | } |
149 | |
150 | } else { |
78cd27b3 |
151 | if (isset($_POST['action']) && $_POST['action']=='cancel') { |
152 | $res = $banana->action_cancelArticle($group, $artid); |
153 | } else { |
154 | $res = ''; |
155 | } |
156 | |
1254696c |
157 | if (!is_null($action)) { |
158 | switch ($action) { |
78cd27b3 |
159 | case 'cancel': |
1f75b135 |
160 | $res .= $banana->action_showArticle($group, $artid, $partid); |
78cd27b3 |
161 | if ($banana->post->checkcancel()) { |
162 | $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>' |
5440bf74 |
163 | . '<form action="' |
f6df9eb2 |
164 | . htmlentities(makeLink(Array('group' => $group, |
165 | 'artid' => $artid))) |
166 | . '" method="post"><p>' |
78cd27b3 |
167 | . '<input type="hidden" name="action" value="cancel" />' |
168 | . '<input type="submit" value="Annuler !" />' |
169 | . '</p></form>'; |
170 | return $form.$res; |
171 | } |
172 | return $res; |
173 | |
174 | case 'new': |
175 | return $banana->action_newFup($group, $artid); |
176 | } |
177 | } |
7a0e2710 |
178 | |
1786dc36 |
179 | if (isset($banana->get['pj'])) { |
1254696c |
180 | $view = false; |
181 | if ($action == 'view') { |
182 | $view = true; |
7a0e2710 |
183 | } |
1254696c |
184 | $att = $banana->action_getAttachment($group, $artid, $banana->get['pj'], $view); |
a1937df3 |
185 | if ($att != "") { |
186 | return $res.$att; |
187 | } |
188 | return ""; |
7a0e2710 |
189 | } |
190 | |
1f75b135 |
191 | return $res . $banana->action_showArticle($group, $artid, $partid); |
78cd27b3 |
192 | } |
193 | } |
194 | |
195 | /**************************************************************************/ |
196 | /* actions */ |
197 | /**************************************************************************/ |
198 | |
199 | function action_saveSubs() |
200 | { |
201 | return; |
202 | } |
203 | |
204 | function action_listGroups() |
205 | { |
206 | $this->_newGroup(); |
207 | |
208 | $cuts = displayshortcuts(); |
209 | $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups->to_html(); |
210 | if (count($this->newgroups->overview)) { |
211 | $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>'; |
212 | $res .= $this->newgroups->to_html(); |
213 | } |
214 | |
215 | $this->nntp->quit(); |
216 | return $res.$cuts; |
217 | } |
218 | |
219 | function action_listSubs() |
220 | { |
221 | $this->_require('groups'); |
222 | $this->groups = new BananaGroups(BANANA_GROUP_ALL); |
223 | |
224 | $cuts = displayshortcuts(); |
225 | $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups->to_html(true).$cuts; |
226 | |
227 | $this->nntp->quit(); |
228 | return $res; |
229 | } |
230 | |
231 | function action_showThread($group, $first) |
232 | { |
856dc84a |
233 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
f37bac43 |
234 | return '<p class="error">'._b_('Impossible charger la liste des messages de ') . $group . '</p>'; |
856dc84a |
235 | } |
78cd27b3 |
236 | |
237 | if ($first > count($this->spool->overview)) { |
238 | $first = count($this->spool->overview); |
239 | } |
240 | |
241 | $first = $first - ($first % $this->tmax) + 1; |
242 | |
243 | $cuts = displayshortcuts($first); |
244 | |
245 | $res = '<h1>'.$group.'</h1>'.$cuts; |
246 | $res .= $this->spool->to_html($first, $first+$this->tmax); |
247 | |
248 | $this->nntp->quit(); |
249 | |
250 | return $res.$cuts; |
251 | } |
252 | |
1f75b135 |
253 | function action_showArticle($group, $id, $part) |
78cd27b3 |
254 | { |
856dc84a |
255 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
f37bac43 |
256 | return '<p class="error">'._b_('Impossible charger la liste des messages de ') . $group . '</p>'; |
856dc84a |
257 | } |
258 | |
259 | if (!$this->_newPost($id)) { |
78cd27b3 |
260 | if ($this->nntp->lasterrorcode == "423") { |
261 | $this->spool->delid($id); |
262 | } |
263 | $this->nntp->quit(); |
264 | return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>'; |
265 | } |
266 | |
267 | $cuts = displayshortcuts(); |
268 | $res = '<h1>'._b_('Message').'</h1>'.$cuts; |
1f75b135 |
269 | $res .= $this->post->to_html($part); |
78cd27b3 |
270 | |
271 | $this->nntp->quit(); |
272 | |
273 | return $res.$cuts; |
274 | } |
275 | |
7a0e2710 |
276 | function action_getAttachment($group, $id, $pjid, $action) |
277 | { |
856dc84a |
278 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
279 | return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>'; |
280 | } |
281 | |
282 | if (!$this->_newPost($id)) { |
7a0e2710 |
283 | if ($this->nntp->lasterrorcode == "423") { |
284 | $this->spool->delid($id); |
285 | } |
286 | $this->nntp->quit(); |
287 | return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>'; |
288 | } |
289 | |
290 | $this->nntp->quit(); |
291 | if ($this->post->get_attachment($pjid, $action)) { |
292 | return ""; |
293 | } else { |
294 | return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>'; |
295 | } |
296 | } |
297 | |
78cd27b3 |
298 | function action_cancelArticle($group, $id) |
299 | { |
856dc84a |
300 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
301 | return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>'; |
302 | } |
303 | |
304 | if (!$this->_newPost($id)) { |
305 | return '<p class="error">'._b_('Impossible de trouver le message à annuler').'</p>'; |
306 | } |
78cd27b3 |
307 | $mid = array_search($id, $this->spool->ids); |
308 | |
309 | if (!$this->post->checkcancel()) { |
310 | return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>'; |
311 | } |
312 | $msg = 'From: '.$this->profile['name']."\n" |
313 | . "Newsgroups: $group\n" |
314 | . "Subject: cmsg $mid\n" |
315 | . $this->custom |
316 | . "Control: cancel $mid\n" |
317 | . "\n" |
318 | . "Message canceled with Banana"; |
319 | if ($this->nntp->post($msg)) { |
320 | $this->spool->delid($id); |
321 | $this->nntp->quit(); |
41b90d00 |
322 | redirectInBanana(Array('group' => $group, |
f6df9eb2 |
323 | 'first' => $id)); |
78cd27b3 |
324 | } else { |
325 | return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>'; |
326 | } |
327 | } |
328 | |
329 | function action_newFup($group, $id = -1) |
330 | { |
331 | $subject = $body = ''; |
332 | $target = $group; |
333 | |
334 | if ($id > 0) { |
335 | $this->nntp->group($group); |
856dc84a |
336 | if ($this->_newPost($id)) { |
78cd27b3 |
337 | $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post->headers['subject']); |
a529ea7b |
338 | $body = utf8_encode($this->post->name." "._b_("a écrit"))." :\n".wrap($this->post->get_body(), "> "); |
78cd27b3 |
339 | $target = isset($this->post->headers['followup-to']) ? $this->post->headers['followup-to'] : $this->post->headers['newsgroups']; |
340 | } |
341 | } |
342 | |
343 | $this->nntp->quit(); |
344 | |
345 | $cuts = displayshortcuts(); |
346 | $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts; |
5440bf74 |
347 | $html .= '<form enctype="multipart/form-data" action="' |
f6df9eb2 |
348 | . htmlentities(makeLink(Array('group' => $group))) |
349 | .'" method="post" accept-charset="utf-8">'; |
78cd27b3 |
350 | $html .= '<table class="bicol" cellpadding="0" cellspacing="0">'; |
351 | $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>'; |
352 | $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile['name']).'</td></tr>'; |
353 | $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>'; |
354 | $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>'; |
355 | $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>'; |
356 | $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile['org'].'</td></tr>'; |
357 | $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>'; |
358 | $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">' |
f12fdb59 |
359 | . to_entities($body).($this->profile['sig'] ? "\n\n-- \n".htmlentities($this->profile['sig']) : '').'</textarea></td></tr>'; |
e9e9463c |
360 | if ($this->can_attach) { |
f6df9eb2 |
361 | $html .= '<tr><th colspan="2">'._b_('Pièce jointe').'</th></tr>'; |
e9e9463c |
362 | $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize.'" />'; |
363 | $html .= '<input type="file" name="newpj" size="40"/></td></tr>'; |
364 | } |
f6df9eb2 |
365 | $html .= '<tr><th colspan="2">'; |
78cd27b3 |
366 | if ($id > 0) { |
367 | $html .= '<input type="hidden" name="artid" value="'.$id.'" />'; |
368 | } |
369 | $html .= '<input type="hidden" name="action" value="new" />'; |
f6df9eb2 |
370 | $html .= '<input type="submit" value="Envoyer le message" /></th></tr>'; |
78cd27b3 |
371 | $html .= '</table></form>'; |
372 | |
373 | return $html.$cuts; |
374 | } |
375 | |
376 | function action_doFup($group, $artid = -1) |
377 | { |
378 | if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name']) |
379 | && is_utf8($_POST['org']) && is_utf8($_POST['body']) ) |
380 | ) { |
381 | foreach(array('subject', 'name', 'org', 'body') as $key) { |
382 | $_POST[$key] = utf8_encode($_POST[$key]); |
383 | } |
384 | } |
fb6bea16 |
385 | |
f6df9eb2 |
386 | $forums = preg_split('/\s*(,|;)\s*/', $_POST['newsgroups']); |
387 | $fup = $_POST['followup']; |
388 | if (sizeof($forums) > 1) { |
389 | if (empty($fup)) { |
390 | $fup = $forums[0]; |
391 | } |
392 | } |
393 | $to = implode(',', $forums); |
394 | |
856dc84a |
395 | if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { |
396 | return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>'; |
397 | } |
f6df9eb2 |
398 | |
78cd27b3 |
399 | $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']); |
d14182c8 |
400 | $msg = 'From: ' . $this->profile['name'] . "\n" |
fb6bea16 |
401 | . "Newsgroups: ". $to . "\n" |
d14182c8 |
402 | . "Subject: " . headerEncode($_POST['subject'], 128) . "\n" |
78cd27b3 |
403 | . (empty($this->profile['org']) ? '' : "Organization: {$this->profile['org']}\n") |
d14182c8 |
404 | . (empty($fup) ? '' : 'Followup-To: ' . $fup . "\n"); |
78cd27b3 |
405 | |
406 | if ($artid != -1) { |
407 | $this->_require('post'); |
408 | $post = new BananaPost($artid); |
856dc84a |
409 | if (!$post || !$post->valid) { |
410 | return '<p class="error">'._b_('Impossible charger le message d\'origine').'</p>'; |
411 | } |
78cd27b3 |
412 | $refs = ( isset($post->headers['references']) ? $post->headers['references']." " : "" ); |
413 | $msg .= "References: $refs{$post->headers['message-id']}\n"; |
414 | } |
415 | |
f12fdb59 |
416 | $body_headers = $this->custom_plain; |
d6f4a433 |
417 | $body = wrap($body, ""); |
0a61409e |
418 | |
419 | // include attachment in the body |
d28aa62d |
420 | $uploaded = $this->_upload('newpj'); |
ef84d640 |
421 | switch ($uploaded['error']) { |
422 | case UPLOAD_ERR_OK: |
f12fdb59 |
423 | $this->custom = $this->custom_mp.$this->custom; |
424 | $body = $this->_make_part($body_headers, $body); |
425 | $file_head = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n" |
426 | . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n" |
427 | . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n"; |
428 | $body .= $this->_make_part($file_head, $uploaded['data']); |
429 | $body .= "\n--".$this->boundary.'--'; |
ef84d640 |
430 | break; |
431 | |
432 | case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: |
433 | return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ') |
434 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
435 | |
436 | case UPLOAD_ERR_PARTIAL: |
437 | return '<p class="error">'._b_('Erreur lors de l\'upload de ') |
438 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
439 | |
440 | case UPLOAD_ERR_NO_FILE: |
441 | return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ') |
442 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
443 | |
444 | case UPLOAD_ERR_NO_TMP_DIR: |
445 | return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ') |
446 | .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid); |
f12fdb59 |
447 | |
448 | default: |
449 | $this->custom = $body_headers.$this->custom; |
d28aa62d |
450 | } |
0a61409e |
451 | |
452 | // finalise and post the message |
453 | $msg .= $this->custom.$this->profile['customhdr']."\n".$body; |
78cd27b3 |
454 | |
455 | if ($this->nntp->post($msg)) { |
f6df9eb2 |
456 | $dir = Array('group' => $group); |
457 | if ($artid != -1) { |
458 | $dir['first'] = $artid; |
459 | } |
41b90d00 |
460 | redirectInBanana($dir); |
78cd27b3 |
461 | } else { |
f0dc6af4 |
462 | return '<p class="error">' . _b_('Impossible de poster le message') . '</p>' |
463 | . $this->action_showThread($group, $artid); |
78cd27b3 |
464 | } |
465 | } |
466 | |
467 | /**************************************************************************/ |
468 | /* Private functions */ |
469 | /**************************************************************************/ |
470 | |
471 | function _newSpool($group, $disp=0, $since='') { |
472 | $this->_require('spool'); |
473 | if (!$this->spool || $this->spool->group != $group) { |
474 | $this->spool = new BananaSpool($group, $disp, $since); |
856dc84a |
475 | if (!$this->spool || !$this->spool->valid) { |
476 | $this->spool = null; |
477 | return false; |
478 | } |
78cd27b3 |
479 | } |
e230b41a |
480 | if (count($this->profile['subscribe']) > 0) { |
481 | $this->_newGroup(false); |
482 | } |
856dc84a |
483 | return true; |
78cd27b3 |
484 | } |
485 | |
486 | function _newPost($id) |
487 | { |
488 | $this->_require('post'); |
489 | $this->post = new BananaPost($id); |
856dc84a |
490 | if (!$this->post || !$this->post->valid) { |
491 | $this->post = null; |
492 | return false; |
493 | } |
494 | return true; |
78cd27b3 |
495 | } |
496 | |
e230b41a |
497 | function _newGroup($showNew = true) |
78cd27b3 |
498 | { |
499 | $this->_require('groups'); |
500 | $this->groups = new BananaGroups(BANANA_GROUP_SUB); |
e230b41a |
501 | if ($showNew && $this->groups->type == BANANA_GROUP_SUB) { |
78cd27b3 |
502 | $this->newgroups = new BananaGroups(BANANA_GROUP_NEW); |
503 | } |
504 | } |
505 | |
506 | function _require($file) |
507 | { |
508 | require_once (dirname(__FILE__).'/'.$file.'.inc.php'); |
509 | } |
d28aa62d |
510 | |
511 | function _upload($file) |
512 | { |
513 | if ($_FILES[$file]['name'] == "") { |
514 | return Array( 'error' => -1 ); |
515 | } |
516 | |
517 | // upload |
518 | $_FILES[$file]['tmp_name']; |
519 | |
520 | // test if upload is ok |
521 | $file = $_FILES[$file]; |
522 | if ($file['size'] == 0 || $file['error'] != 0) { |
523 | if ($file['error'] == 0) { |
524 | $file['error'] = -1; |
525 | } |
526 | return $file; |
527 | } |
528 | |
529 | // adding custum data |
530 | $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :( |
531 | $encod = 'base64'; |
532 | if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) { |
533 | $mime = $format[1]; |
534 | $encod = $format[2]; |
535 | } |
536 | $data = fread(fopen($file['tmp_name'], 'r'), $file['size']); |
537 | if ($encod == 'base64') { |
538 | $data = chunk_split(base64_encode($data)); |
539 | } |
540 | $file['name'] = basename($file['name']); |
541 | $file['type'] = $mime; |
542 | $file['encoding'] = $encod; |
543 | $file['data'] = $data; |
544 | |
545 | return $file; |
546 | } |
f12fdb59 |
547 | |
548 | function _make_part($headers, $body) |
549 | { |
550 | return "\n--".$this->boundary."\n".$headers."\n".$body; |
551 | } |
78cd27b3 |
552 | } |
553 | |
f6df9eb2 |
554 | // vim:set et sw=4 sts=4 ts=4 |
78cd27b3 |
555 | ?> |