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