Source for file attachment_common.php

Documentation is available at attachment_common.php

  1. <?php
  2. /**
  3. * attachment_common.php
  4. *
  5. * This file provides the handling of often-used attachment types.
  6. *
  7. * @copyright 1999-2020 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: attachment_common.php 14840 2020年01月07日 07:42:38Z pdontthink $
  10. * @package squirrelmail
  11. */
  12. /**
  13. * FIXME Needs phpDocumentator style documentation
  14. */
  15. require_once(SM_PATH . 'functions/global.php');
  16. global $attachment_common_show_images_list;
  17. $attachment_common_show_images_list = array();
  18. global $FileExtensionToMimeType, $attachment_common_types;
  19. $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
  20. 'gif' => 'image/gif',
  21. 'htm' => 'text/html',
  22. 'html' => 'text/html',
  23. 'jpg' => 'image/jpeg',
  24. 'jpeg' => 'image/jpeg',
  25. 'php' => 'text/plain',
  26. 'png' => 'image/png',
  27. 'rtf' => 'text/richtext',
  28. 'txt' => 'text/plain',
  29. 'patch'=> 'text/plain',
  30. 'vcf' => 'text/x-vcard');
  31. /* Register browser-supported image types */
  32. sqgetGlobalVar ('attachment_common_types', $attachment_common_types);
  33. if (isset($attachment_common_types)) {
  34. // var is used to detect activation of jpeg image types
  35. unset($jpeg_done);
  36. /* Don't run this before being logged in. That may happen
  37. when plugins include mime.php */
  38. foreach ($attachment_common_types as $val => $v) {
  39. if ($val == 'image/gif')
  40. register_attachment_common ('image/gif', 'link_image');
  41. elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
  42. (!isset($jpeg_done))) {
  43. $jpeg_done = 1;
  44. register_attachment_common ('image/jpeg', 'link_image');
  45. register_attachment_common ('image/pjpeg', 'link_image');
  46. }
  47. elseif ($val == 'image/png')
  48. register_attachment_common ('image/png', 'link_image');
  49. elseif ($val == 'image/x-xbitmap')
  50. register_attachment_common ('image/x-xbitmap', 'link_image');
  51. elseif ($val == '*/*' || $val == 'image/*') {
  52. /**
  53. * browser (Firefox) declared that anything is acceptable.
  54. * Lets register some common image types.
  55. */
  56. if (! isset($jpeg_done)) {
  57. $jpeg_done = 1;
  58. register_attachment_common ('image/jpeg', 'link_image');
  59. register_attachment_common ('image/pjpeg', 'link_image');
  60. }
  61. register_attachment_common ('image/gif', 'link_image');
  62. register_attachment_common ('image/png', 'link_image');
  63. register_attachment_common ('image/x-xbitmap', 'link_image');
  64. }
  65. }
  66. unset($jpeg_done);
  67. }
  68. /* Register text-type attachments */
  69. register_attachment_common ('message/rfc822', 'link_message');
  70. register_attachment_common ('text/plain', 'link_text');
  71. register_attachment_common ('text/richtext', 'link_text');
  72. /* Register HTML */
  73. register_attachment_common ('text/html', 'link_html');
  74. /* Register vcards */
  75. register_attachment_common ('text/x-vcard', 'link_vcard');
  76. register_attachment_common ('text/directory', 'link_vcard');
  77. /* Register rules for general types.
  78. * These will be used if there isn't a more specific rule available. */
  79. register_attachment_common ('text/*', 'link_text');
  80. register_attachment_common ('message/*', 'link_text');
  81. /* Register "unknown" attachments */
  82. register_attachment_common ('application/octet-stream', 'octet_stream');
  83. /* Function which optimizes readability of the above code */
  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. function attachment_common_link_text (&$Args) {
  90. global $squirrelmail_attachments_finished_handling;
  91. // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense?? For now, I've added the entity ID to make it unique
  92. if (!empty($squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]])) return;
  93. $squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]] = TRUE;
  94. /* If there is a text attachment, we would like to create a "View" button
  95. that links to the text attachment viewer.
  96. $Args[1] = the array of actions
  97. Use the name of this file for adding an action
  98. $Args[1]['attachment_common'] = Array for href and text
  99. $Args[1]['attachment_common']['text'] = What is displayed
  100. $Args[1]['attachment_common']['href'] = Where it links to */
  101. sqgetGlobalVar ('QUERY_STRING', $QUERY_STRING, SQ_SERVER );
  102. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING;
  103. $Args[1]['attachment_common']['href'] =
  104. set_url_var ($Args[1]['attachment_common']['href'],
  105. 'ent_id',$Args[5]);
  106. /* The link that we created needs a name. */
  107. $Args[1]['attachment_common']['text'] = _ ("View");
  108. /* Each attachment has a filename on the left, which is a link.
  109. Where that link points to can be changed. Just in case the link above
  110. for viewing text attachments is not the same as the default link for
  111. this file, we'll change it.
  112. This is a lot better in the image links, since the defaultLink will just
  113. download the image, but the one that we set it to will format the page
  114. to have an image tag in the center (looking a lot like this text viewer) */
  115. $Args[6] = $Args[1]['attachment_common']['href'];
  116. }
  117. function attachment_common_link_message (&$Args) {
  118. global $squirrelmail_attachments_finished_handling;
  119. // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense?? For now, I've added the entity ID to make it unique
  120. if (!empty($squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]])) return;
  121. $squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]] = TRUE;
  122. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/read_body.php?startMessage=' .
  123. $Args[2] . '&amp;passed_id=' . $Args[3] . '&amp;mailbox=' . $Args[4] .
  124. '&amp;passed_ent_id=' . $Args[5] . '&amp;override_type0=message&amp;override_type1=rfc822';
  125. $Args[1]['attachment_common']['text'] = _ ("View");
  126. $Args[6] = $Args[1]['attachment_common']['href'];
  127. }
  128. function attachment_common_link_html (&$Args) {
  129. global $squirrelmail_attachments_finished_handling;
  130. // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense?? For now, I've added the entity ID to make it unique
  131. if (!empty($squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]])) return;
  132. $squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]] = TRUE;
  133. sqgetGlobalVar ('QUERY_STRING', $QUERY_STRING, SQ_SERVER );
  134. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING.
  135. /* why use the overridetype? can this be removed */
  136. '&amp;override_type0=text&amp;override_type1=html';
  137. $Args[1]['attachment_common']['href'] =
  138. set_url_var ($Args[1]['attachment_common']['href'],
  139. 'ent_id',$Args[5]);
  140. $Args[1]['attachment_common']['text'] = _ ("View");
  141. $Args[6] = $Args[1]['attachment_common']['href'];
  142. }
  143. function attachment_common_link_image (&$Args) {
  144. global $squirrelmail_attachments_finished_handling;
  145. // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense?? For now, I've added the entity ID to make it unique
  146. if (!empty($squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]])) return;
  147. $squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]] = TRUE;
  148. global $attachment_common_show_images, $attachment_common_show_images_list;
  149. sqgetGlobalVar ('QUERY_STRING', $QUERY_STRING, SQ_SERVER );
  150. $info['passed_id'] = $Args[3];
  151. $info['mailbox'] = $Args[4];
  152. $info['ent_id'] = $Args[5];
  153. $attachment_common_show_images_list[] = $info;
  154. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/image.php?'. $QUERY_STRING;
  155. $Args[1]['attachment_common']['href'] =
  156. set_url_var ($Args[1]['attachment_common']['href'],
  157. 'ent_id',$Args[5]);
  158. $Args[1]['attachment_common']['text'] = _ ("View");
  159. $Args[6] = $Args[1]['attachment_common']['href'];
  160. }
  161. function attachment_common_link_vcard (&$Args) {
  162. global $squirrelmail_attachments_finished_handling;
  163. // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense?? For now, I've added the entity ID to make it unique
  164. if (!empty($squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]])) return;
  165. $squirrelmail_attachments_finished_handling[$Args[7] . $Args[5]] = TRUE;
  166. sqgetGlobalVar ('QUERY_STRING', $QUERY_STRING, SQ_SERVER );
  167. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/vcard.php?'. $QUERY_STRING;
  168. $Args[1]['attachment_common']['href'] =
  169. set_url_var ($Args[1]['attachment_common']['href'],
  170. 'ent_id',$Args[5]);
  171. $Args[1]['attachment_common']['text'] = _ ("View Business Card");
  172. $Args[6] = $Args[1]['attachment_common']['href'];
  173. }
  174. function attachment_common_octet_stream (&$Args) {
  175. global $FileExtensionToMimeType;
  176. do_hook ('attachment_common-load_mime_types');
  177. preg_match ('/\.([^.]+)$/', $Args[7], $Regs);
  178. $Ext = '';
  179. if (is_array ($Regs) && isset($Regs[1])) {
  180. $Ext = $Regs[1];
  181. $Ext = strtolower ($Regs[1]);
  182. }
  183. if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
  184. return;
  185. $Ret = do_hook ('attachment ' . $FileExtensionToMimeType[$Ext],
  186. $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
  187. $Args[7], $Args[8], $Args[9]);
  188. foreach ($Ret as $a => $b) {
  189. $Args[$a] = $b;
  190. }
  191. }

Documentation generated on 2020年1月13日 04:24:14 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /