7baf86a9 |
1 | <?php |
7350889b |
2 | |
35586184 |
3 | /** |
4 | * attachment_common.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 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 | * |
31841a9e |
11 | * @version $Id$ |
d6c32258 |
12 | * @package squirrelmail |
3169f064 |
13 | * @todo document attachment $type hook arguments |
35586184 |
14 | */ |
7baf86a9 |
15 | |
3169f064 |
16 | /** @ignore */ |
17 | if (! defined('SM_PATH')) define('SM_PATH','../'); |
18 | |
19 | /** sqgetGlobalVar() */ |
20 | include_once(SM_PATH . 'functions/global.php'); |
21 | /** sqm_baseuri() */ |
22 | include_once(SM_PATH . 'functions/display_messages.php'); |
cd21d1aa |
23 | |
35586184 |
24 | global $attachment_common_show_images_list; |
25 | $attachment_common_show_images_list = array(); |
bbdd6ddb |
26 | |
5bc6067b |
27 | global $FileExtensionToMimeType, $attachment_common_types; |
4691e788 |
28 | /** |
29 | * Mapping of file extensions to mime types |
30 | * |
31 | * Used for application/octet-stream mime type detection. |
32 | * Supported extensions: bmp, gif, htm, html, jpg, jpeg, php, |
33 | * png, rtf, txt, patch (since 1.4.2), vcf |
34 | * @global array $FileExtensionToMimeType |
35 | */ |
5bc6067b |
36 | $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap', |
37 | 'gif' => 'image/gif', |
38 | 'htm' => 'text/html', |
39 | 'html' => 'text/html', |
40 | 'jpg' => 'image/jpeg', |
41 | 'jpeg' => 'image/jpeg', |
42 | 'php' => 'text/plain', |
43 | 'png' => 'image/png', |
44 | 'rtf' => 'text/richtext', |
45 | 'txt' => 'text/plain', |
ab8b558f |
46 | 'patch'=> 'text/plain', |
5bc6067b |
47 | 'vcf' => 'text/x-vcard'); |
48 | |
49 | /* Register browser-supported image types */ |
b455793d |
50 | sqgetGlobalVar('attachment_common_types', $attachment_common_types); |
4691e788 |
51 | // FIXME: do we use $attachment_common_types that is not extracted by sqgetGlobalVar() ? |
5bc6067b |
52 | if (isset($attachment_common_types)) { |
4691e788 |
53 | // var is used to detect activation of jpeg image types |
54 | unset($jpeg_done); |
5bc6067b |
55 | /* Don't run this before being logged in. That may happen |
56 | when plugins include mime.php */ |
57 | foreach ($attachment_common_types as $val => $v) { |
7baf86a9 |
58 | if ($val == 'image/gif') |
5bc6067b |
59 | register_attachment_common('image/gif', 'link_image'); |
7baf86a9 |
60 | elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and |
61 | (!isset($jpeg_done))) { |
5bc6067b |
62 | $jpeg_done = 1; |
63 | register_attachment_common('image/jpeg', 'link_image'); |
64 | register_attachment_common('image/pjpeg', 'link_image'); |
4691e788 |
65 | // register_attachment_common('image/jpg', 'link_image'); |
7baf86a9 |
66 | } |
67 | elseif ($val == 'image/png') |
5bc6067b |
68 | register_attachment_common('image/png', 'link_image'); |
7baf86a9 |
69 | elseif ($val == 'image/x-xbitmap') |
5bc6067b |
70 | register_attachment_common('image/x-xbitmap', 'link_image'); |
4691e788 |
71 | elseif ($val == '*/*' || $val == 'image/*') { |
72 | /** |
73 | * browser (Firefox) declared that anything is acceptable. |
74 | * Lets register some common image types. |
75 | */ |
76 | if (! isset($jpeg_done)) { |
77 | $jpeg_done = 1; |
78 | register_attachment_common('image/jpeg', 'link_image'); |
79 | register_attachment_common('image/pjpeg', 'link_image'); |
80 | // register_attachment_common('image/jpg', 'link_image'); |
81 | } |
82 | register_attachment_common('image/gif', 'link_image'); |
83 | register_attachment_common('image/png', 'link_image'); |
84 | register_attachment_common('image/x-xbitmap', 'link_image'); |
85 | // register_attachment_common('image/x-ico', 'link_image'); |
86 | // register_attachment_common('image/x-icon', 'link_image'); |
87 | // register_attachment_common('image/bmp', 'link_image'); |
88 | // register_attachment_common('image/x-ms-bmp', 'link_image'); |
89 | } |
5bc6067b |
90 | } |
91 | unset($jpeg_done); |
92 | } |
7baf86a9 |
93 | |
5bc6067b |
94 | /* Register text-type attachments */ |
679f13b7 |
95 | register_attachment_common('message/rfc822', 'link_message'); |
5bc6067b |
96 | register_attachment_common('text/plain', 'link_text'); |
97 | register_attachment_common('text/richtext', 'link_text'); |
7baf86a9 |
98 | |
5bc6067b |
99 | /* Register HTML */ |
100 | register_attachment_common('text/html', 'link_html'); |
7baf86a9 |
101 | |
5bc6067b |
102 | /* Register vcards */ |
103 | register_attachment_common('text/x-vcard', 'link_vcard'); |
35036cf9 |
104 | register_attachment_common('text/directory', 'link_vcard'); |
7baf86a9 |
105 | |
ae2f65a9 |
106 | /* Register rules for general types. |
107 | * These will be used if there isn't a more specific rule available. */ |
108 | register_attachment_common('text/*', 'link_text'); |
109 | register_attachment_common('message/*', 'link_text'); |
110 | |
5bc6067b |
111 | /* Register "unknown" attachments */ |
112 | register_attachment_common('application/octet-stream', 'octet_stream'); |
7baf86a9 |
113 | |
114 | |
3169f064 |
115 | /** |
116 | * Function which optimizes readability of the above code |
117 | * Registers 'attachment $type' hooks. |
118 | * @param string $type attachment type |
119 | * @param string $func suffix of attachment_common_* function, which handles $type attachments. |
120 | * @since 1.2.0 |
121 | */ |
7baf86a9 |
122 | function register_attachment_common($type, $func) { |
5bc6067b |
123 | global $squirrelmail_plugin_hooks; |
124 | $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] = |
7baf86a9 |
125 | 'attachment_common_' . $func; |
126 | } |
127 | |
3169f064 |
128 | /** |
129 | * Adds href and text keys to attachment_common array for text attachments |
130 | * @param array $Args attachment $type hook arguments |
131 | * @since 1.2.0 |
132 | */ |
21dab2dc |
133 | function attachment_common_link_text(&$Args) { |
134 | /* If there is a text attachment, we would like to create a "View" button |
5bc6067b |
135 | that links to the text attachment viewer. |
62f7daa5 |
136 | |
5bc6067b |
137 | $Args[1] = the array of actions |
62f7daa5 |
138 | |
21dab2dc |
139 | Use the name of this file for adding an action |
140 | $Args[1]['attachment_common'] = Array for href and text |
62f7daa5 |
141 | |
5bc6067b |
142 | $Args[1]['attachment_common']['text'] = What is displayed |
21dab2dc |
143 | $Args[1]['attachment_common']['href'] = Where it links to */ |
961ca3d8 |
144 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
846a3a21 |
145 | |
3169f064 |
146 | // if htmlspecialchars() breaks something - find other way to encode & in url. |
147 | $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING); |
98eb617f |
148 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
149 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
150 | 'ent_id',$Args[5]); |
62f7daa5 |
151 | |
21dab2dc |
152 | /* The link that we created needs a name. */ |
153 | $Args[1]['attachment_common']['text'] = _("View"); |
679f13b7 |
154 | |
5bc6067b |
155 | /* Each attachment has a filename on the left, which is a link. |
156 | Where that link points to can be changed. Just in case the link above |
157 | for viewing text attachments is not the same as the default link for |
158 | this file, we'll change it. |
62f7daa5 |
159 | |
5bc6067b |
160 | This is a lot better in the image links, since the defaultLink will just |
161 | download the image, but the one that we set it to will format the page |
162 | to have an image tag in the center (looking a lot like this text viewer) */ |
163 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
164 | } |
165 | |
3169f064 |
166 | /** |
167 | * Adds href and text keys to attachment_common array for rfc822 attachments |
168 | * @param array $Args attachment $type hook arguments |
169 | * @since 1.2.6 |
170 | */ |
21dab2dc |
171 | function attachment_common_link_message(&$Args) { |
3169f064 |
172 | $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/read_body.php?startMessage=' . |
679f13b7 |
173 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
174 | '&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822'; |
21dab2dc |
175 | |
176 | $Args[1]['attachment_common']['text'] = _("View"); |
f4c8a5ab |
177 | |
62f7daa5 |
178 | $Args[6] = $Args[1]['attachment_common']['href']; |
679f13b7 |
179 | } |
180 | |
3169f064 |
181 | /** |
182 | * Adds href and text keys to attachment_common array for html attachments |
183 | * @param array $Args attachment $type hook arguments |
184 | * @since 1.2.0 |
185 | */ |
21dab2dc |
186 | function attachment_common_link_html(&$Args) { |
961ca3d8 |
187 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
846a3a21 |
188 | |
3169f064 |
189 | $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING). |
190 | /* why use the overridetype? can this be removed */ |
191 | /* override_type might be needed only when we want view other type of messages as html */ |
47f9a69d |
192 | '&override_type0=text&override_type1=html'; |
193 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
194 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
195 | 'ent_id',$Args[5]); |
5bc6067b |
196 | |
21dab2dc |
197 | $Args[1]['attachment_common']['text'] = _("View"); |
5bc6067b |
198 | |
199 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
200 | } |
201 | |
3169f064 |
202 | /** |
f8a1ed5a |
203 | * Adds href and text keys to attachment_common array for image attachments |
3169f064 |
204 | * @param array $Args attachment $type hook arguments |
205 | * @since 1.2.0 |
206 | */ |
21dab2dc |
207 | function attachment_common_link_image(&$Args) { |
ce68b76b |
208 | global $attachment_common_show_images_list; |
846a3a21 |
209 | |
961ca3d8 |
210 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
62f7daa5 |
211 | |
5bc6067b |
212 | $info['passed_id'] = $Args[3]; |
213 | $info['mailbox'] = $Args[4]; |
214 | $info['ent_id'] = $Args[5]; |
62f7daa5 |
215 | |
5bc6067b |
216 | $attachment_common_show_images_list[] = $info; |
62f7daa5 |
217 | |
3169f064 |
218 | $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/image.php?'. htmlspecialchars($QUERY_STRING); |
ff9d4297 |
219 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
220 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
221 | 'ent_id',$Args[5]); |
62f7daa5 |
222 | |
21dab2dc |
223 | $Args[1]['attachment_common']['text'] = _("View"); |
62f7daa5 |
224 | |
5bc6067b |
225 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
226 | } |
227 | |
3169f064 |
228 | /** |
f8a1ed5a |
229 | * Adds href and text keys to attachment_common array for vcard attachments |
3169f064 |
230 | * @param array $Args attachment $type hook arguments |
231 | * @since 1.2.0 |
232 | */ |
21dab2dc |
233 | function attachment_common_link_vcard(&$Args) { |
961ca3d8 |
234 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
62f7daa5 |
235 | |
3169f064 |
236 | $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING); |
ff9d4297 |
237 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
238 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
239 | 'ent_id',$Args[5]); |
62f7daa5 |
240 | |
c9fec394 |
241 | $Args[1]['attachment_common']['text'] = _("View Business Card"); |
62f7daa5 |
242 | |
5bc6067b |
243 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
244 | } |
245 | |
3169f064 |
246 | /** |
247 | * Processes octet-stream attachments. |
f8a1ed5a |
248 | * Calls attachment_common-load_mime_types and attachment $type hooks. |
3169f064 |
249 | * @param array $Args attachment $type hook arguments |
250 | * @since 1.2.0 |
251 | */ |
21dab2dc |
252 | function attachment_common_octet_stream(&$Args) { |
5bc6067b |
253 | global $FileExtensionToMimeType; |
62f7daa5 |
254 | |
5bc6067b |
255 | do_hook('attachment_common-load_mime_types'); |
62f7daa5 |
256 | |
5bc6067b |
257 | ereg('\\.([^\\.]+)$', $Args[7], $Regs); |
62f7daa5 |
258 | |
5bc6067b |
259 | $Ext = strtolower($Regs[1]); |
62f7daa5 |
260 | |
5bc6067b |
261 | if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext])) |
62f7daa5 |
262 | return; |
263 | |
264 | $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext], |
265 | $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], |
5bc6067b |
266 | $Args[7], $Args[8], $Args[9]); |
62f7daa5 |
267 | |
5bc6067b |
268 | foreach ($Ret as $a => $b) { |
269 | $Args[$a] = $b; |
270 | } |
7baf86a9 |
271 | } |
272 | |
62f7daa5 |
273 | ?> |