7baf86a9 |
1 | <?php |
7350889b |
2 | |
35586184 |
3 | /** |
4 | * attachment_common.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This file provides the handling of often-used attachment types. |
10 | * |
11 | * $Id$ |
12 | */ |
7baf86a9 |
13 | |
35586184 |
14 | global $attachment_common_show_images_list; |
15 | $attachment_common_show_images_list = array(); |
bbdd6ddb |
16 | |
5bc6067b |
17 | global $FileExtensionToMimeType, $attachment_common_types; |
18 | $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap', |
19 | 'gif' => 'image/gif', |
20 | 'htm' => 'text/html', |
21 | 'html' => 'text/html', |
22 | 'jpg' => 'image/jpeg', |
23 | 'jpeg' => 'image/jpeg', |
24 | 'php' => 'text/plain', |
25 | 'png' => 'image/png', |
26 | 'rtf' => 'text/richtext', |
27 | 'txt' => 'text/plain', |
28 | 'vcf' => 'text/x-vcard'); |
29 | |
30 | /* Register browser-supported image types */ |
829035a8 |
31 | sqextractGlobalVar('attachment_common_types'); |
5bc6067b |
32 | if (isset($attachment_common_types)) { |
33 | /* Don't run this before being logged in. That may happen |
34 | when plugins include mime.php */ |
35 | foreach ($attachment_common_types as $val => $v) { |
7baf86a9 |
36 | if ($val == 'image/gif') |
5bc6067b |
37 | register_attachment_common('image/gif', 'link_image'); |
7baf86a9 |
38 | elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and |
39 | (!isset($jpeg_done))) { |
5bc6067b |
40 | $jpeg_done = 1; |
41 | register_attachment_common('image/jpeg', 'link_image'); |
42 | register_attachment_common('image/pjpeg', 'link_image'); |
7baf86a9 |
43 | } |
44 | elseif ($val == 'image/png') |
5bc6067b |
45 | register_attachment_common('image/png', 'link_image'); |
7baf86a9 |
46 | elseif ($val == 'image/x-xbitmap') |
5bc6067b |
47 | register_attachment_common('image/x-xbitmap', 'link_image'); |
48 | } |
49 | unset($jpeg_done); |
50 | } |
7baf86a9 |
51 | |
5bc6067b |
52 | /* Register text-type attachments */ |
679f13b7 |
53 | //register_attachment_common('message/rfc822', 'link_text'); |
54 | register_attachment_common('message/rfc822', 'link_message'); |
5bc6067b |
55 | register_attachment_common('text/plain', 'link_text'); |
56 | register_attachment_common('text/richtext', 'link_text'); |
7baf86a9 |
57 | |
5bc6067b |
58 | /* Register HTML */ |
59 | register_attachment_common('text/html', 'link_html'); |
7baf86a9 |
60 | |
ae2f65a9 |
61 | |
5bc6067b |
62 | /* Register vcards */ |
63 | register_attachment_common('text/x-vcard', 'link_vcard'); |
7baf86a9 |
64 | |
ae2f65a9 |
65 | /* Register rules for general types. |
66 | * These will be used if there isn't a more specific rule available. */ |
67 | register_attachment_common('text/*', 'link_text'); |
68 | register_attachment_common('message/*', 'link_text'); |
69 | |
5bc6067b |
70 | /* Register "unknown" attachments */ |
71 | register_attachment_common('application/octet-stream', 'octet_stream'); |
7baf86a9 |
72 | |
73 | |
74 | /* Function which optimizes readability of the above code */ |
75 | |
76 | function register_attachment_common($type, $func) { |
5bc6067b |
77 | global $squirrelmail_plugin_hooks; |
78 | $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] = |
7baf86a9 |
79 | 'attachment_common_' . $func; |
80 | } |
81 | |
82 | |
83 | function attachment_common_link_text(&$Args) |
84 | { |
5bc6067b |
85 | /* If there is a text attachment, we would like to create a 'view' button |
86 | that links to the text attachment viewer. |
87 | |
88 | $Args[1] = the array of actions |
89 | |
90 | Use our plugin name for adding an action |
91 | $Args[1]['attachment_common'] = array for href and text |
92 | |
93 | $Args[1]['attachment_common']['text'] = What is displayed |
94 | $Args[1]['attachment_common']['href'] = Where it links to |
95 | |
96 | This sets the 'href' of this plugin for a new link. */ |
846a3a21 |
97 | $QUERY_STRING = $_SERVER['QUERY_STRING'];; |
98 | |
3bf87aae |
99 | $Args[1]['attachment_common']['href'] = '../src/view_text.php?'. $QUERY_STRING; |
98eb617f |
100 | $Args[1]['attachment_common']['href'] = |
101 | set_url_var($Args[1]['attachment_common']['href'], |
b854f93a |
102 | 'ent_id',$Args[5]); |
7baf86a9 |
103 | |
5bc6067b |
104 | /* The link that we created needs a name. "view" will be displayed for |
105 | all text attachments handled by this plugin. */ |
106 | $Args[1]['attachment_common']['text'] = _("view"); |
679f13b7 |
107 | |
5bc6067b |
108 | /* Each attachment has a filename on the left, which is a link. |
109 | Where that link points to can be changed. Just in case the link above |
110 | for viewing text attachments is not the same as the default link for |
111 | this file, we'll change it. |
112 | |
113 | This is a lot better in the image links, since the defaultLink will just |
114 | download the image, but the one that we set it to will format the page |
115 | to have an image tag in the center (looking a lot like this text viewer) */ |
116 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
117 | } |
118 | |
679f13b7 |
119 | function attachment_common_link_message(&$Args) |
120 | { |
f4c8a5ab |
121 | $Args[1]['attachment_common']['href'] = '../src/read_body.php?startMessage=' . |
679f13b7 |
122 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
123 | '&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822'; |
124 | /* The link that we created needs a name. "view" will be displayed for |
125 | all text attachments handled by this plugin. */ |
126 | $Args[1]['attachment_common']['text'] = _("view"); |
f4c8a5ab |
127 | |
128 | $Args[6] = $Args[1]['attachment_common']['href']; |
679f13b7 |
129 | } |
130 | |
131 | |
846a3a21 |
132 | function attachment_common_link_html(&$Args) |
7baf86a9 |
133 | { |
846a3a21 |
134 | $QUERY_STRING = $_SERVER['QUERY_STRING'];; |
135 | |
47f9a69d |
136 | $Args[1]['attachment_common']['href'] = '../src/view_text.php?'. $QUERY_STRING. |
137 | /* why use the overridetype? can this be removed */ |
138 | '&override_type0=text&override_type1=html'; |
139 | $Args[1]['attachment_common']['href'] = |
140 | set_url_var($Args[1]['attachment_common']['href'], |
141 | 'ent_id',$Args[5]); |
5bc6067b |
142 | |
143 | $Args[1]['attachment_common']['text'] = _("view"); |
144 | |
145 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
146 | } |
147 | |
7baf86a9 |
148 | function attachment_common_link_image(&$Args) |
149 | { |
846a3a21 |
150 | $QUERY_STRING = $_SERVER['QUERY_STRING'];; |
5bc6067b |
151 | global $attachment_common_show_images, $attachment_common_show_images_list; |
846a3a21 |
152 | |
5bc6067b |
153 | |
154 | $info['passed_id'] = $Args[3]; |
155 | $info['mailbox'] = $Args[4]; |
156 | $info['ent_id'] = $Args[5]; |
157 | |
158 | $attachment_common_show_images_list[] = $info; |
159 | |
ff9d4297 |
160 | $Args[1]['attachment_common']['href'] = '../src/image.php?'. $QUERY_STRING; |
161 | $Args[1]['attachment_common']['href'] = |
162 | set_url_var($Args[1]['attachment_common']['href'], |
163 | 'ent_id',$Args[5]); |
cd7b8833 |
164 | |
5bc6067b |
165 | $Args[1]['attachment_common']['text'] = _("view"); |
166 | |
167 | $Args[6] = $Args[1]['attachment_common']['href']; |
f4c8a5ab |
168 | |
7baf86a9 |
169 | } |
170 | |
171 | |
172 | function attachment_common_link_vcard(&$Args) |
173 | { |
846a3a21 |
174 | $QUERY_STRING = $_SERVER['QUERY_STRING'];; |
175 | |
ff9d4297 |
176 | $Args[1]['attachment_common']['href'] = '../src/vcard.php?'. $QUERY_STRING; |
177 | $Args[1]['attachment_common']['href'] = |
178 | set_url_var($Args[1]['attachment_common']['href'], |
179 | 'ent_id',$Args[5]); |
5bc6067b |
180 | |
181 | $Args[1]['attachment_common']['text'] = _("Business Card"); |
182 | |
183 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
184 | } |
185 | |
186 | |
187 | function attachment_common_octet_stream(&$Args) |
188 | { |
5bc6067b |
189 | global $FileExtensionToMimeType; |
7baf86a9 |
190 | |
5bc6067b |
191 | do_hook('attachment_common-load_mime_types'); |
7baf86a9 |
192 | |
5bc6067b |
193 | ereg('\\.([^\\.]+)$', $Args[7], $Regs); |
7baf86a9 |
194 | |
5bc6067b |
195 | $Ext = strtolower($Regs[1]); |
7baf86a9 |
196 | |
5bc6067b |
197 | if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext])) |
198 | return; |
7baf86a9 |
199 | |
5bc6067b |
200 | $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext], |
201 | $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], |
202 | $Args[7], $Args[8], $Args[9]); |
7baf86a9 |
203 | |
5bc6067b |
204 | foreach ($Ret as $a => $b) { |
205 | $Args[$a] = $b; |
206 | } |
7baf86a9 |
207 | } |
208 | |
ae2f65a9 |
209 | ?> |