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