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 |
35586184 |
13 | */ |
7baf86a9 |
14 | |
d6c32258 |
15 | /** |
21dab2dc |
16 | * FIXME Needs phpDocumentator style documentation |
d6c32258 |
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', |
ab8b558f |
34 | 'patch'=> 'text/plain', |
5bc6067b |
35 | 'vcf' => 'text/x-vcard'); |
36 | |
37 | /* Register browser-supported image types */ |
b455793d |
38 | sqgetGlobalVar('attachment_common_types', $attachment_common_types); |
5bc6067b |
39 | if (isset($attachment_common_types)) { |
40 | /* Don't run this before being logged in. That may happen |
41 | when plugins include mime.php */ |
42 | foreach ($attachment_common_types as $val => $v) { |
7baf86a9 |
43 | if ($val == 'image/gif') |
5bc6067b |
44 | register_attachment_common('image/gif', 'link_image'); |
7baf86a9 |
45 | elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and |
46 | (!isset($jpeg_done))) { |
5bc6067b |
47 | $jpeg_done = 1; |
48 | register_attachment_common('image/jpeg', 'link_image'); |
49 | register_attachment_common('image/pjpeg', 'link_image'); |
7baf86a9 |
50 | } |
51 | elseif ($val == 'image/png') |
5bc6067b |
52 | register_attachment_common('image/png', 'link_image'); |
7baf86a9 |
53 | elseif ($val == 'image/x-xbitmap') |
5bc6067b |
54 | register_attachment_common('image/x-xbitmap', 'link_image'); |
55 | } |
56 | unset($jpeg_done); |
57 | } |
7baf86a9 |
58 | |
5bc6067b |
59 | /* Register text-type attachments */ |
679f13b7 |
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 | |
21dab2dc |
90 | function attachment_common_link_text(&$Args) { |
91 | /* If there is a text attachment, we would like to create a "View" button |
5bc6067b |
92 | that links to the text attachment viewer. |
62f7daa5 |
93 | |
5bc6067b |
94 | $Args[1] = the array of actions |
62f7daa5 |
95 | |
21dab2dc |
96 | Use the name of this file for adding an action |
97 | $Args[1]['attachment_common'] = Array for href and text |
62f7daa5 |
98 | |
5bc6067b |
99 | $Args[1]['attachment_common']['text'] = What is displayed |
21dab2dc |
100 | $Args[1]['attachment_common']['href'] = Where it links to */ |
961ca3d8 |
101 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
846a3a21 |
102 | |
961ca3d8 |
103 | $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING; |
98eb617f |
104 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
105 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
106 | 'ent_id',$Args[5]); |
62f7daa5 |
107 | |
21dab2dc |
108 | /* The link that we created needs a name. */ |
109 | $Args[1]['attachment_common']['text'] = _("View"); |
679f13b7 |
110 | |
5bc6067b |
111 | /* Each attachment has a filename on the left, which is a link. |
112 | Where that link points to can be changed. Just in case the link above |
113 | for viewing text attachments is not the same as the default link for |
114 | this file, we'll change it. |
62f7daa5 |
115 | |
5bc6067b |
116 | This is a lot better in the image links, since the defaultLink will just |
117 | download the image, but the one that we set it to will format the page |
118 | to have an image tag in the center (looking a lot like this text viewer) */ |
119 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
120 | } |
121 | |
21dab2dc |
122 | function attachment_common_link_message(&$Args) { |
961ca3d8 |
123 | $Args[1]['attachment_common']['href'] = SM_PATH . 'src/read_body.php?startMessage=' . |
679f13b7 |
124 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
125 | '&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822'; |
21dab2dc |
126 | |
127 | $Args[1]['attachment_common']['text'] = _("View"); |
f4c8a5ab |
128 | |
62f7daa5 |
129 | $Args[6] = $Args[1]['attachment_common']['href']; |
679f13b7 |
130 | } |
131 | |
132 | |
21dab2dc |
133 | function attachment_common_link_html(&$Args) { |
961ca3d8 |
134 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
846a3a21 |
135 | |
961ca3d8 |
136 | $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING. |
47f9a69d |
137 | /* why use the overridetype? can this be removed */ |
138 | '&override_type0=text&override_type1=html'; |
139 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
140 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
141 | 'ent_id',$Args[5]); |
5bc6067b |
142 | |
21dab2dc |
143 | $Args[1]['attachment_common']['text'] = _("View"); |
5bc6067b |
144 | |
145 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
146 | } |
147 | |
21dab2dc |
148 | function attachment_common_link_image(&$Args) { |
ce68b76b |
149 | global $attachment_common_show_images_list; |
846a3a21 |
150 | |
961ca3d8 |
151 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
62f7daa5 |
152 | |
5bc6067b |
153 | $info['passed_id'] = $Args[3]; |
154 | $info['mailbox'] = $Args[4]; |
155 | $info['ent_id'] = $Args[5]; |
62f7daa5 |
156 | |
5bc6067b |
157 | $attachment_common_show_images_list[] = $info; |
62f7daa5 |
158 | |
961ca3d8 |
159 | $Args[1]['attachment_common']['href'] = SM_PATH . 'src/image.php?'. $QUERY_STRING; |
ff9d4297 |
160 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
161 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
162 | 'ent_id',$Args[5]); |
62f7daa5 |
163 | |
21dab2dc |
164 | $Args[1]['attachment_common']['text'] = _("View"); |
62f7daa5 |
165 | |
5bc6067b |
166 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
167 | } |
168 | |
169 | |
21dab2dc |
170 | function attachment_common_link_vcard(&$Args) { |
961ca3d8 |
171 | sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); |
62f7daa5 |
172 | |
961ca3d8 |
173 | $Args[1]['attachment_common']['href'] = SM_PATH . 'src/vcard.php?'. $QUERY_STRING; |
ff9d4297 |
174 | $Args[1]['attachment_common']['href'] = |
62f7daa5 |
175 | set_url_var($Args[1]['attachment_common']['href'], |
21dab2dc |
176 | 'ent_id',$Args[5]); |
62f7daa5 |
177 | |
c9fec394 |
178 | $Args[1]['attachment_common']['text'] = _("View Business Card"); |
62f7daa5 |
179 | |
5bc6067b |
180 | $Args[6] = $Args[1]['attachment_common']['href']; |
7baf86a9 |
181 | } |
182 | |
183 | |
21dab2dc |
184 | function attachment_common_octet_stream(&$Args) { |
5bc6067b |
185 | global $FileExtensionToMimeType; |
62f7daa5 |
186 | |
5bc6067b |
187 | do_hook('attachment_common-load_mime_types'); |
62f7daa5 |
188 | |
5bc6067b |
189 | ereg('\\.([^\\.]+)$', $Args[7], $Regs); |
62f7daa5 |
190 | |
5bc6067b |
191 | $Ext = strtolower($Regs[1]); |
62f7daa5 |
192 | |
5bc6067b |
193 | if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext])) |
62f7daa5 |
194 | return; |
195 | |
196 | $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext], |
197 | $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], |
5bc6067b |
198 | $Args[7], $Args[8], $Args[9]); |
62f7daa5 |
199 | |
5bc6067b |
200 | foreach ($Ret as $a => $b) { |
201 | $Args[$a] = $b; |
202 | } |
7baf86a9 |
203 | } |
204 | |
62f7daa5 |
205 | ?> |