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