Source for file attachment_common.php

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

Documentation generated on Fri, 31 Oct 2014 04:20:22 +0100 by phpDocumentor 1.4.3