Plugin may be invisible when JS is not detected
[squirrelmail.git] / plugins / newmail / loadfile.php
CommitLineData
dbc7cd0a 1<?php
2/**
3 * SquirrelMail NewMail plugin
4 *
5 * Script loads user's media file.
6 * @version $Id$
7 * @package plugins
fb883255 8 * @subpackage newmail
dbc7cd0a 9 */
10
197562c9 11/**
12 * define SM_PATH
13 * @ignore
14 */
dbc7cd0a 15define('SM_PATH','../../');
16
17/** Load squirrelmail functions */
18include_once(SM_PATH . 'include/validate.php');
19/** Load plugin functions */
20include_once(SM_PATH . 'plugins/newmail/functions.php');
21
22sqgetGlobalVar('username',$username,SQ_SESSION);
23global $data_dir;
24
25$media = getPref($data_dir,$username,'newmail_media', '(none)');
fb883255 26// get other prefs
27$newmail_userfile_type=getPref($data_dir,$username,'newmail_userfile_type',false);
dbc7cd0a 28
fb883255 29$newmail_userfile_location=getHashedFile($username, $data_dir, $username . '.sound');
dbc7cd0a 30
fb883255 31if ($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);
dbc7cd0a 38
fb883255 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 }
dbc7cd0a 65
fb883255 66 // make sure that media file is in correct format
67 $newmail_userfile_extension=newmail_detect_filetype($newmail_userfile_contents,$newmail_userfile_contenttype);
dbc7cd0a 68
fb883255 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.
dbc7cd0a 81// maybe we should send some error code
82?>