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 | /*****************************************************************/ |
15 | /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ |
16 | /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ |
17 | /*** + Base level indent should begin at left margin, as ***/ |
18 | /*** the $attachment_common_show_images_list stuff below. ***/ |
19 | /*** + All identation should consist of four space blocks ***/ |
20 | /*** + Tab characters are evil. ***/ |
21 | /*** + all comments should use "slash-star ... star-slash" ***/ |
22 | /*** style -- no pound characters, no slash-slash style ***/ |
23 | /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ |
24 | /*** ALWAYS USE { AND } CHARACTERS!!! ***/ |
25 | /*** + Please use ' instead of ", when possible. Note " ***/ |
26 | /*** should always be used in _( ) function calls. ***/ |
27 | /*** Thank you for your help making the SM code more readable. ***/ |
28 | /*****************************************************************/ |
29 | |
30 | global $attachment_common_show_images_list; |
31 | $attachment_common_show_images_list = array(); |
bbdd6ddb |
32 | |
7baf86a9 |
33 | global $FileExtensionToMimeType, $attachment_common_types; |
34 | $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap', |
35 | 'gif' => 'image/gif', |
36 | 'htm' => 'text/html', |
37 | 'html' => 'text/html', |
38 | 'jpg' => 'image/jpeg', |
39 | 'jpeg' => 'image/jpeg', |
40 | 'php' => 'text/plain', |
41 | 'png' => 'image/png', |
42 | 'rtf' => 'text/richtext', |
43 | 'txt' => 'text/plain', |
44 | 'vcf' => 'text/x-vcard'); |
45 | |
46 | // Register browser-supported image types |
47 | if (isset($attachment_common_types)) { |
48 | // Don't run this before being logged in. That may happen |
49 | // when plugins include mime.php |
50 | foreach ($attachment_common_types as $val => $v) { |
51 | if ($val == 'image/gif') |
52 | register_attachment_common('image/gif', 'link_image'); |
53 | elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and |
54 | (!isset($jpeg_done))) { |
55 | $jpeg_done = 1; |
56 | register_attachment_common('image/jpeg', 'link_image'); |
57 | register_attachment_common('image/pjpeg', 'link_image'); |
58 | } |
59 | elseif ($val == 'image/png') |
60 | register_attachment_common('image/png', 'link_image'); |
61 | elseif ($val == 'image/x-xbitmap') |
62 | register_attachment_common('image/x-xbitmap', 'link_image'); |
63 | } |
64 | unset($jpeg_done); |
65 | } |
66 | |
67 | // Register text-type attachments |
68 | register_attachment_common('message/rfc822', 'link_text'); |
69 | register_attachment_common('text/plain', 'link_text'); |
70 | register_attachment_common('text/richtext', 'link_text'); |
71 | |
72 | // Register HTML |
73 | register_attachment_common('text/html', 'link_html'); |
74 | |
75 | // Register vcards |
76 | register_attachment_common('text/x-vcard', 'link_vcard'); |
77 | |
78 | // Register "unknown" attachments |
79 | register_attachment_common('application/octet-stream', 'octet_stream'); |
80 | |
81 | |
82 | /* Function which optimizes readability of the above code */ |
83 | |
84 | function register_attachment_common($type, $func) { |
85 | global $squirrelmail_plugin_hooks; |
86 | $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] = |
87 | 'attachment_common_' . $func; |
88 | } |
89 | |
90 | |
91 | function attachment_common_link_text(&$Args) |
92 | { |
93 | // If there is a text attachment, we would like to create a 'view' button |
94 | // that links to the text attachment viewer. |
95 | // |
96 | // $Args[1] = the array of actions |
97 | // |
98 | // Use our plugin name for adding an action |
99 | // $Args[1]['attachment_common'] = array for href and text |
100 | // |
101 | // $Args[1]['attachment_common']['text'] = What is displayed |
102 | // $Args[1]['attachment_common']['href'] = Where it links to |
103 | // |
104 | // This sets the 'href' of this plugin for a new link. |
105 | $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' . |
106 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
107 | '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=plain'; |
108 | |
109 | // If we got here from a search, we should preserve these variables |
110 | if ($Args[8] && $Args[9]) |
111 | $Args[1]['attachment_common']['href'] .= '&where=' . |
112 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
113 | |
114 | // The link that we created needs a name. "view" will be displayed for |
115 | // all text attachments handled by this plugin. |
116 | $Args[1]['attachment_common']['text'] = _("view"); |
117 | |
118 | // Each attachment has a filename on the left, which is a link. |
119 | // Where that link points to can be changed. Just in case the link above |
120 | // for viewing text attachments is not the same as the default link for |
121 | // this file, we'll change it. |
122 | // |
123 | // This is a lot better in the image links, since the defaultLink will just |
124 | // download the image, but the one that we set it to will format the page |
125 | // to have an image tag in the center (looking a lot like this text viewer) |
126 | $Args[6] = $Args[1]['attachment_common']['href']; |
127 | } |
128 | |
129 | |
130 | function attachment_common_link_html(&$Args) |
131 | { |
132 | $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' . |
133 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
134 | '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=html'; |
135 | |
136 | if ($Args[8] && $Args[9]) |
137 | $Args[1]['attachment_common']['href'] .= '&where=' . |
138 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
139 | |
140 | $Args[1]['attachment_common']['text'] = _("view"); |
141 | |
142 | $Args[6] = $Args[1]['attachment_common']['href']; |
143 | } |
144 | |
145 | |
146 | function attachment_common_link_image(&$Args) |
147 | { |
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 | |
156 | $Args[1]['attachment_common']['href'] = '../src/image.php?startMessage=' . |
157 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
158 | '&passed_ent_id=' . $Args[5]; |
159 | |
160 | if ($Args[8] && $Args[9]) |
161 | $Args[1]['attachment_common']['href'] .= '&where=' . |
162 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
163 | |
164 | $Args[1]['attachment_common']['text'] = _("view"); |
165 | |
166 | $Args[6] = $Args[1]['attachment_common']['href']; |
167 | } |
168 | |
169 | |
170 | function attachment_common_link_vcard(&$Args) |
171 | { |
172 | $Args[1]['attachment_common']['href'] = '../src/vcard.php?startMessage=' . |
173 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
174 | '&passed_ent_id=' . $Args[5]; |
175 | |
176 | if (isset($where) && isset($what)) |
177 | $Args[1]['attachment_common']['href'] .= '&where=' . |
178 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
179 | |
180 | $Args[1]['attachment_common']['text'] = _("Business Card"); |
181 | |
182 | $Args[6] = $Args[1]['attachment_common']['href']; |
183 | } |
184 | |
185 | |
186 | function attachment_common_octet_stream(&$Args) |
187 | { |
188 | global $FileExtensionToMimeType; |
189 | |
190 | do_hook('attachment_common-load_mime_types'); |
191 | |
192 | ereg('\\.([^\\.]+)$', $Args[7], $Regs); |
193 | |
194 | $Ext = strtolower($Regs[1]); |
195 | |
196 | if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext])) |
197 | return; |
198 | |
199 | $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext], |
200 | $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], |
201 | $Args[7], $Args[8], $Args[9]); |
202 | |
203 | foreach ($Ret as $a => $b) { |
204 | $Args[$a] = $b; |
205 | } |
206 | } |
207 | |
208 | ?> |