Replaced ereg_replace with str_replace on several occasions, should be faster.
[squirrelmail.git] / functions / attachment_common.php
... / ...
CommitLineData
1<?php
2
3/**
4 * attachment_common.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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 */
13
14global $attachment_common_show_images_list;
15$attachment_common_show_images_list = array();
16
17global $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 */
31if (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) {
35 if ($val == 'image/gif')
36 register_attachment_common('image/gif', 'link_image');
37 elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
38 (!isset($jpeg_done))) {
39 $jpeg_done = 1;
40 register_attachment_common('image/jpeg', 'link_image');
41 register_attachment_common('image/pjpeg', 'link_image');
42 }
43 elseif ($val == 'image/png')
44 register_attachment_common('image/png', 'link_image');
45 elseif ($val == 'image/x-xbitmap')
46 register_attachment_common('image/x-xbitmap', 'link_image');
47 }
48 unset($jpeg_done);
49}
50
51/* Register text-type attachments */
52register_attachment_common('message/rfc822', 'link_text');
53register_attachment_common('text/plain', 'link_text');
54register_attachment_common('text/richtext', 'link_text');
55
56/* Register HTML */
57register_attachment_common('text/html', 'link_html');
58
59/* Register vcards */
60register_attachment_common('text/x-vcard', 'link_vcard');
61
62/* Register "unknown" attachments */
63register_attachment_common('application/octet-stream', 'octet_stream');
64
65
66/* Function which optimizes readability of the above code */
67
68function register_attachment_common($type, $func) {
69 global $squirrelmail_plugin_hooks;
70 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
71 'attachment_common_' . $func;
72}
73
74
75function attachment_common_link_text(&$Args)
76{
77 /* If there is a text attachment, we would like to create a 'view' button
78 that links to the text attachment viewer.
79
80 $Args[1] = the array of actions
81
82 Use our plugin name for adding an action
83 $Args[1]['attachment_common'] = array for href and text
84
85 $Args[1]['attachment_common']['text'] = What is displayed
86 $Args[1]['attachment_common']['href'] = Where it links to
87
88 This sets the 'href' of this plugin for a new link. */
89 $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' .
90 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
91 '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=plain';
92
93 /* If we got here from a search, we should preserve these variables */
94 if ($Args[8] && $Args[9])
95 $Args[1]['attachment_common']['href'] .= '&where=' .
96 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
97
98 /* The link that we created needs a name. "view" will be displayed for
99 all text attachments handled by this plugin. */
100 $Args[1]['attachment_common']['text'] = _("view");
101
102 /* Each attachment has a filename on the left, which is a link.
103 Where that link points to can be changed. Just in case the link above
104 for viewing text attachments is not the same as the default link for
105 this file, we'll change it.
106
107 This is a lot better in the image links, since the defaultLink will just
108 download the image, but the one that we set it to will format the page
109 to have an image tag in the center (looking a lot like this text viewer) */
110 $Args[6] = $Args[1]['attachment_common']['href'];
111}
112
113
114function attachment_common_link_html(&$Args)
115{
116 $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' .
117 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
118 '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=html';
119
120 if ($Args[8] && $Args[9]) {
121 $Args[1]['attachment_common']['href'] .= '&where=' .
122 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
123 }
124
125 $Args[1]['attachment_common']['text'] = _("view");
126
127 $Args[6] = $Args[1]['attachment_common']['href'];
128}
129
130
131function attachment_common_link_image(&$Args)
132{
133 global $attachment_common_show_images, $attachment_common_show_images_list;
134
135 $info['passed_id'] = $Args[3];
136 $info['mailbox'] = $Args[4];
137 $info['ent_id'] = $Args[5];
138
139 $attachment_common_show_images_list[] = $info;
140
141 $Args[1]['attachment_common']['href'] = '../src/image.php?startMessage=' .
142 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
143 '&passed_ent_id=' . $Args[5];
144
145 if ($Args[8] && $Args[9]) {
146 $Args[1]['attachment_common']['href'] .= '&where=' .
147 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
148 }
149
150 $Args[1]['attachment_common']['text'] = _("view");
151
152 $Args[6] = $Args[1]['attachment_common']['href'];
153
154}
155
156
157function attachment_common_link_vcard(&$Args)
158{
159 $Args[1]['attachment_common']['href'] = '../src/vcard.php?startMessage=' .
160 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
161 '&passed_ent_id=' . $Args[5];
162
163 if (isset($where) && isset($what))
164 $Args[1]['attachment_common']['href'] .= '&where=' .
165 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
166
167 $Args[1]['attachment_common']['text'] = _("Business Card");
168
169 $Args[6] = $Args[1]['attachment_common']['href'];
170}
171
172
173function attachment_common_octet_stream(&$Args)
174{
175 global $FileExtensionToMimeType;
176
177 do_hook('attachment_common-load_mime_types');
178
179 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
180
181 $Ext = strtolower($Regs[1]);
182
183 if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
184 return;
185
186 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
187 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
188 $Args[7], $Args[8], $Args[9]);
189
190 foreach ($Ret as $a => $b) {
191 $Args[$a] = $b;
192 }
193}
194
195?>