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 &copy; 1999-2006 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: attachment_common.php,v 1.25.2.9 2006/04/14 22:27:07 jervfors Exp $
  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.     /* If there is a text attachment, we would like to create a "View" button
  107.        that links to the text attachment viewer.
  108.  
  109.        $Args[1] = the array of actions
  110.  
  111.        Use the name of this file for adding an action
  112.        $Args[1]['attachment_common'] = Array for href and text
  113.  
  114.        $Args[1]['attachment_common']['text'] = What is displayed
  115.        $Args[1]['attachment_common']['href'] = Where it links to */
  116.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  117.  
  118.     $Args[1]['attachment_common']['href'SM_PATH 'src/view_text.php?'$QUERY_STRING;
  119.     $Args[1]['attachment_common']['href'=
  120.           set_url_var($Args[1]['attachment_common']['href'],
  121.           'ent_id',$Args[5]);
  122.  
  123.     /* The link that we created needs a name. */
  124.     $Args[1]['attachment_common']['text'_("View");
  125.  
  126.     /* Each attachment has a filename on the left, which is a link.
  127.        Where that link points to can be changed.  Just in case the link above
  128.        for viewing text attachments is not the same as the default link for
  129.        this file, we'll change it.
  130.  
  131.        This is a lot better in the image links, since the defaultLink will just
  132.        download the image, but the one that we set it to will format the page
  133.        to have an image tag in the center (looking a lot like this text viewer) */
  134.     $Args[6$Args[1]['attachment_common']['href'];
  135. }
  136.  
  137. function attachment_common_link_message(&$Args{
  138.     $Args[1]['attachment_common']['href'SM_PATH 'src/read_body.php?startMessage=' .
  139.         $Args[2'&amp;passed_id=' $Args[3'&amp;mailbox=' $Args[4.
  140.         '&amp;passed_ent_id=' $Args[5'&amp;override_type0=message&amp;override_type1=rfc822';
  141.  
  142.     $Args[1]['attachment_common']['text'_("View");
  143.  
  144.     $Args[6$Args[1]['attachment_common']['href'];
  145. }
  146.  
  147.  
  148. function attachment_common_link_html(&$Args{
  149.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  150.  
  151.     $Args[1]['attachment_common']['href'SM_PATH 'src/view_text.php?'$QUERY_STRING.
  152.        /* why use the overridetype? can this be removed */
  153.        '&amp;override_type0=text&amp;override_type1=html';
  154.     $Args[1]['attachment_common']['href'=
  155.           set_url_var($Args[1]['attachment_common']['href'],
  156.           'ent_id',$Args[5]);
  157.  
  158.     $Args[1]['attachment_common']['text'_("View");
  159.  
  160.     $Args[6$Args[1]['attachment_common']['href'];
  161. }
  162.  
  163. function attachment_common_link_image(&$Args{
  164.     global $attachment_common_show_images$attachment_common_show_images_list;
  165.  
  166.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  167.  
  168.     $info['passed_id'$Args[3];
  169.     $info['mailbox'$Args[4];
  170.     $info['ent_id'$Args[5];
  171.  
  172.     $attachment_common_show_images_list[$info;
  173.  
  174.     $Args[1]['attachment_common']['href'SM_PATH 'src/image.php?'$QUERY_STRING;
  175.     $Args[1]['attachment_common']['href'=
  176.           set_url_var($Args[1]['attachment_common']['href'],
  177.           'ent_id',$Args[5]);
  178.  
  179.     $Args[1]['attachment_common']['text'_("View");
  180.  
  181.     $Args[6$Args[1]['attachment_common']['href'];
  182. }
  183.  
  184.  
  185. function attachment_common_link_vcard(&$Args{
  186.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  187.  
  188.     $Args[1]['attachment_common']['href'SM_PATH 'src/vcard.php?'$QUERY_STRING;
  189.     $Args[1]['attachment_common']['href'=
  190.           set_url_var($Args[1]['attachment_common']['href'],
  191.           'ent_id',$Args[5]);
  192.  
  193.     $Args[1]['attachment_common']['text'_("View Business Card");
  194.  
  195.     $Args[6$Args[1]['attachment_common']['href'];
  196. }
  197.  
  198.  
  199. function attachment_common_octet_stream(&$Args{
  200.     global $FileExtensionToMimeType;
  201.  
  202.     do_hook('attachment_common-load_mime_types');
  203.  
  204.     ereg('\\.([^\\.]+)$'$Args[7]$Regs);
  205.  
  206.     $Ext strtolower($Regs[1]);
  207.  
  208.     if ($Ext == '' || isset($FileExtensionToMimeType[$Ext]))
  209.         return;
  210.  
  211.     $Ret do_hook('attachment ' $FileExtensionToMimeType[$Ext],
  212.         $Args[1]$Args[2]$Args[3]$Args[4]$Args[5]$Args[6],
  213.         $Args[7]$Args[8]$Args[9]);
  214.  
  215.     foreach ($Ret as $a => $b{
  216.         $Args[$a$b;
  217.     }
  218. }
  219.  
  220. ?>

Documentation generated on Sat, 07 Oct 2006 16:29:54 +0300 by phpDocumentor 1.3.0RC6