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