phpDocumentor updates
[squirrelmail.git] / functions / attachment_common.php
1 <?php
2
3 /**
4 * attachment_common.php
5 *
6 * This file provides the handling of often-used attachment types.
7 *
8 * @copyright &copy; 1999-2005 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 * @todo document attachment $type hook arguments
13 */
14
15 /** @ignore */
16 if (! defined('SM_PATH')) define('SM_PATH','../');
17
18 /** sqgetGlobalVar() */
19 include_once(SM_PATH . 'functions/global.php');
20 /** sqm_baseuri() */
21 include_once(SM_PATH . 'functions/display_messages.php');
22
23 global $attachment_common_show_images_list;
24 $attachment_common_show_images_list = array();
25
26 global $FileExtensionToMimeType, $attachment_common_types;
27 /**
28 * Mapping of file extensions to mime types
29 *
30 * Used for application/octet-stream mime type detection.
31 * Supported extensions: bmp, gif, htm, html, jpg, jpeg, php,
32 * png, rtf, txt, patch (since 1.4.2), vcf
33 * @global array $FileExtensionToMimeType
34 */
35 $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
36 'gif' => 'image/gif',
37 'htm' => 'text/html',
38 'html' => 'text/html',
39 'jpg' => 'image/jpeg',
40 'jpeg' => 'image/jpeg',
41 'php' => 'text/plain',
42 'png' => 'image/png',
43 'rtf' => 'text/richtext',
44 'txt' => 'text/plain',
45 'patch'=> 'text/plain',
46 'vcf' => 'text/x-vcard');
47
48 /* Register browser-supported image types */
49 sqgetGlobalVar('attachment_common_types', $attachment_common_types);
50 // FIXME: do we use $attachment_common_types that is not extracted by sqgetGlobalVar() ?
51 if (isset($attachment_common_types)) {
52 // var is used to detect activation of jpeg image types
53 unset($jpeg_done);
54 /* Don't run this before being logged in. That may happen
55 when plugins include mime.php */
56 foreach ($attachment_common_types as $val => $v) {
57 if ($val == 'image/gif')
58 register_attachment_common('image/gif', 'link_image');
59 elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
60 (!isset($jpeg_done))) {
61 $jpeg_done = 1;
62 register_attachment_common('image/jpeg', 'link_image');
63 register_attachment_common('image/pjpeg', 'link_image');
64 // register_attachment_common('image/jpg', 'link_image');
65 }
66 elseif ($val == 'image/png')
67 register_attachment_common('image/png', 'link_image');
68 elseif ($val == 'image/x-xbitmap')
69 register_attachment_common('image/x-xbitmap', 'link_image');
70 elseif ($val == '*/*' || $val == 'image/*') {
71 /**
72 * browser (Firefox) declared that anything is acceptable.
73 * Lets register some common image types.
74 */
75 if (! isset($jpeg_done)) {
76 $jpeg_done = 1;
77 register_attachment_common('image/jpeg', 'link_image');
78 register_attachment_common('image/pjpeg', 'link_image');
79 // register_attachment_common('image/jpg', 'link_image');
80 }
81 register_attachment_common('image/gif', 'link_image');
82 register_attachment_common('image/png', 'link_image');
83 register_attachment_common('image/x-xbitmap', 'link_image');
84 // register_attachment_common('image/x-ico', 'link_image');
85 // register_attachment_common('image/x-icon', 'link_image');
86 // register_attachment_common('image/bmp', 'link_image');
87 // register_attachment_common('image/x-ms-bmp', 'link_image');
88 }
89 }
90 unset($jpeg_done);
91 }
92
93 /* Register text-type attachments */
94 register_attachment_common('message/rfc822', 'link_message');
95 register_attachment_common('text/plain', 'link_text');
96 register_attachment_common('text/richtext', 'link_text');
97
98 /* Register HTML */
99 register_attachment_common('text/html', 'link_html');
100
101 /* Register vcards */
102 register_attachment_common('text/x-vcard', 'link_vcard');
103 register_attachment_common('text/directory', 'link_vcard');
104
105 /* Register rules for general types.
106 * These will be used if there isn't a more specific rule available. */
107 register_attachment_common('text/*', 'link_text');
108 register_attachment_common('message/*', 'link_text');
109
110 /* Register "unknown" attachments */
111 register_attachment_common('application/octet-stream', 'octet_stream');
112
113
114 /**
115 * Function which optimizes readability of the above code
116 * Registers 'attachment $type' hooks.
117 * @param string $type attachment type
118 * @param string $func suffix of attachment_common_* function, which handles $type attachments.
119 * @since 1.2.0
120 */
121 function register_attachment_common($type, $func) {
122 global $squirrelmail_plugin_hooks;
123 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
124 'attachment_common_' . $func;
125 }
126
127 /**
128 * Adds href and text keys to attachment_common array for text attachments
129 * @param array $Args attachment $type hook arguments
130 * @since 1.2.0
131 */
132 function attachment_common_link_text(&$Args) {
133 /* If there is a text attachment, we would like to create a "View" button
134 that links to the text attachment viewer.
135
136 $Args[1] = the array of actions
137
138 Use the name of this file for adding an action
139 $Args[1]['attachment_common'] = Array for href and text
140
141 $Args[1]['attachment_common']['text'] = What is displayed
142 $Args[1]['attachment_common']['href'] = Where it links to */
143 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
144
145 // if htmlspecialchars() breaks something - find other way to encode & in url.
146 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
147 $Args[1]['attachment_common']['href'] =
148 set_url_var($Args[1]['attachment_common']['href'],
149 'ent_id',$Args[5]);
150
151 /* The link that we created needs a name. */
152 $Args[1]['attachment_common']['text'] = _("View");
153
154 /* Each attachment has a filename on the left, which is a link.
155 Where that link points to can be changed. Just in case the link above
156 for viewing text attachments is not the same as the default link for
157 this file, we'll change it.
158
159 This is a lot better in the image links, since the defaultLink will just
160 download the image, but the one that we set it to will format the page
161 to have an image tag in the center (looking a lot like this text viewer) */
162 $Args[6] = $Args[1]['attachment_common']['href'];
163 }
164
165 /**
166 * Adds href and text keys to attachment_common array for rfc822 attachments
167 * @param array $Args attachment $type hook arguments
168 * @since 1.2.6
169 */
170 function attachment_common_link_message(&$Args) {
171 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/read_body.php?startMessage=' .
172 $Args[2] . '&amp;passed_id=' . $Args[3] . '&amp;mailbox=' . $Args[4] .
173 '&amp;passed_ent_id=' . $Args[5] . '&amp;override_type0=message&amp;override_type1=rfc822';
174
175 $Args[1]['attachment_common']['text'] = _("View");
176
177 $Args[6] = $Args[1]['attachment_common']['href'];
178 }
179
180 /**
181 * Adds href and text keys to attachment_common array for html attachments
182 * @param array $Args attachment $type hook arguments
183 * @since 1.2.0
184 */
185 function attachment_common_link_html(&$Args) {
186 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
187
188 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
189 /* why use the overridetype? can this be removed */
190 /* override_type might be needed only when we want view other type of messages as html */
191 '&amp;override_type0=text&amp;override_type1=html';
192 $Args[1]['attachment_common']['href'] =
193 set_url_var($Args[1]['attachment_common']['href'],
194 'ent_id',$Args[5]);
195
196 $Args[1]['attachment_common']['text'] = _("View");
197
198 $Args[6] = $Args[1]['attachment_common']['href'];
199 }
200
201 /**
202 * Adds href and text keys to attachment_common array for image attachments
203 * @param array $Args attachment $type hook arguments
204 * @since 1.2.0
205 */
206 function attachment_common_link_image(&$Args) {
207 global $attachment_common_show_images_list;
208
209 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
210
211 $info['passed_id'] = $Args[3];
212 $info['mailbox'] = $Args[4];
213 $info['ent_id'] = $Args[5];
214
215 $attachment_common_show_images_list[] = $info;
216
217 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
218 $Args[1]['attachment_common']['href'] =
219 set_url_var($Args[1]['attachment_common']['href'],
220 'ent_id',$Args[5]);
221
222 $Args[1]['attachment_common']['text'] = _("View");
223
224 $Args[6] = $Args[1]['attachment_common']['href'];
225 }
226
227 /**
228 * Adds href and text keys to attachment_common array for vcard attachments
229 * @param array $Args attachment $type hook arguments
230 * @since 1.2.0
231 */
232 function attachment_common_link_vcard(&$Args) {
233 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
234
235 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
236 $Args[1]['attachment_common']['href'] =
237 set_url_var($Args[1]['attachment_common']['href'],
238 'ent_id',$Args[5]);
239
240 $Args[1]['attachment_common']['text'] = _("View Business Card");
241
242 $Args[6] = $Args[1]['attachment_common']['href'];
243 }
244
245 /**
246 * Processes octet-stream attachments.
247 * Calls attachment_common-load_mime_types and attachment $type hooks.
248 * @param array $Args attachment $type hook arguments
249 * @since 1.2.0
250 */
251 function attachment_common_octet_stream(&$Args) {
252 global $FileExtensionToMimeType;
253
254 do_hook('attachment_common-load_mime_types');
255
256 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
257
258 $Ext = strtolower($Regs[1]);
259
260 if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
261 return;
262
263 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
264 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
265 $Args[7], $Args[8], $Args[9]);
266
267 foreach ($Ret as $a => $b) {
268 $Args[$a] = $b;
269 }
270 }
271
272 ?>