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