dbc7cd0a |
1 | <?php |
4b4abf93 |
2 | |
dbc7cd0a |
3 | /** |
4 | * SquirrelMail NewMail plugin |
5 | * |
6 | * Script loads user's media file. |
4b4abf93 |
7 | * |
c0d96801 |
8 | * @copyright 2001-2012 The SquirrelMail Project Team |
4b4abf93 |
9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
dbc7cd0a |
10 | * @version $Id$ |
11 | * @package plugins |
fb883255 |
12 | * @subpackage newmail |
dbc7cd0a |
13 | */ |
14 | |
197562c9 |
15 | /** |
202bcbcc |
16 | * Path for SquirrelMail required files. |
197562c9 |
17 | * @ignore |
18 | */ |
202bcbcc |
19 | require('../../include/init.php'); |
dbc7cd0a |
20 | /** Load plugin functions */ |
21 | include_once(SM_PATH . 'plugins/newmail/functions.php'); |
22 | |
23 | sqgetGlobalVar('username',$username,SQ_SESSION); |
24 | global $data_dir; |
25 | |
26 | $media = getPref($data_dir,$username,'newmail_media', '(none)'); |
fb883255 |
27 | // get other prefs |
28 | $newmail_userfile_type=getPref($data_dir,$username,'newmail_userfile_type',false); |
f8a1ed5a |
29 | |
fb883255 |
30 | $newmail_userfile_location=getHashedFile($username, $data_dir, $username . '.sound'); |
dbc7cd0a |
31 | |
f9710f76 |
32 | if ($newmail_uploadsounds && $newmail_userfile_type!=false && file_exists($newmail_userfile_location)) { |
fb883255 |
33 | // open media file |
34 | $newmail_userfile_handle = fopen($newmail_userfile_location,'rb'); |
35 | if ($newmail_userfile_handle) { |
36 | $newmail_userfile_filesize = filesize($newmail_userfile_location); |
37 | $newmail_userfile_contents = fread($newmail_userfile_handle,$newmail_userfile_filesize); |
38 | fclose ($newmail_userfile_handle); |
dbc7cd0a |
39 | |
fb883255 |
40 | // user prefs use only integer values to store file type |
41 | switch($newmail_userfile_type) { |
42 | case SM_NEWMAIL_FILETYPE_WAV: |
43 | // wav file |
44 | $newmail_userfile_contenttype='audio/x-wav'; |
45 | break; |
46 | case SM_NEWMAIL_FILETYPE_MP3: |
47 | // mp3 file |
48 | $newmail_userfile_contenttype='audio/mpeg'; |
49 | break; |
50 | case SM_NEWMAIL_FILETYPE_OGG: |
51 | // ogg file |
52 | $newmail_userfile_contenttype='application/ogg'; |
53 | break; |
54 | case SM_NEWMAIL_FILETYPE_SWF: |
55 | // flash file |
56 | $newmail_userfile_contenttype='application/x-shockwave-flash'; |
57 | break; |
58 | case SM_NEWMAIL_FILETYPE_SVG: |
59 | // svg file |
60 | $newmail_userfile_contenttype='image/svg+xml'; |
61 | break; |
62 | default: |
63 | // none of above |
64 | $newmail_userfile_contenttype='unknown'; |
65 | } |
dbc7cd0a |
66 | |
fb883255 |
67 | // make sure that media file is in correct format |
68 | $newmail_userfile_extension=newmail_detect_filetype($newmail_userfile_contents,$newmail_userfile_contenttype); |
dbc7cd0a |
69 | |
fb883255 |
70 | // last check before sending file contents to browser. |
71 | if ($newmail_userfile_extension!=false) { |
72 | $newmail_send_filename='mediafile.' . $newmail_userfile_extension; |
73 | header ('Content-Disposition: inline; filename="' . $newmail_send_filename . '"'); |
74 | header('Content-Type: "' . $newmail_userfile_contenttype .'"; ' . |
75 | 'name="' . $newmail_send_filename . '"'); |
76 | header('Content-Length: ' . $newmail_userfile_filesize ); |
77 | echo $newmail_userfile_contents; |
78 | exit; |
79 | } // file type detection failed |
80 | } // failed to open userfile |
81 | } // userfile is missing or preferences don't store file type. |
dbc7cd0a |
82 | // maybe we should send some error code |