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