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