Source for file message_list_util.php

Documentation is available at message_list_util.php

  1. <?php
  2.  
  3. /**
  4.  * message_list_util.php
  5.  *
  6.  * Helper functions for message list templates.
  7.  *
  8.  * The following functions are utility functions for templates. Do not
  9.  * echo output in these functions.
  10.  *
  11.  * @copyright 2005-2020 The SquirrelMail Project Team
  12.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  13.  * @version $Id: message_list_util.php 14845 2020-01-07 08:09:34Z pdontthink $
  14.  * @package squirrelmail
  15.  */
  16.  
  17.  
  18. /**
  19.  * @param array $aOrder 
  20.  * @return array 
  21.  */
  22. function calcMessageListColumnWidth($aOrder{
  23.     /**
  24.      * Width of the displayed columns
  25.      */
  26.     $aWidthTpl array(
  27.         SQM_COL_CHECK => 1,
  28.         SQM_COL_FROM =>  25,
  29.         SQM_COL_DATE => 15,
  30.         SQM_COL_SUBJ  => 100,
  31.         SQM_COL_FLAGS => 2,
  32.         SQM_COL_SIZE  => 5,
  33.         SQM_COL_PRIO => 1,
  34.         SQM_COL_ATTACHMENT => 1,
  35.         SQM_COL_INT_DATE => 15,
  36.         SQM_COL_TO => 25,
  37.         SQM_COL_CC => 25,
  38.         SQM_COL_BCC => 25
  39.     );
  40.  
  41.     /**
  42.      * Calculate the width of the subject column based on the
  43.      * widths of the other columns
  44.      */
  45.     if (isset($aOrder[SQM_COL_SUBJ])) {
  46.         foreach($aOrder as $iCol{
  47.             if ($iCol != SQM_COL_SUBJ{
  48.                 $aWidthTpl[SQM_COL_SUBJ-= $aWidthTpl[$iCol];
  49.             }
  50.         }
  51.     }
  52.     $aWidth array();
  53.     foreach($aOrder as $iCol{
  54.         $aWidth[$iCol$aWidthTpl[$iCol];
  55.     }
  56.  
  57.     $iCheckTotalWidth $iTotalWidth 0;
  58.     foreach($aOrder as $iCol$iTotalWidth += $aWidth[$iCol];}
  59.  
  60.     $iTotalWidth ($iTotalWidth$iTotalWidth 100// divide by zero check. shouldn't be needed
  61.  
  62.     // correct the width to 100%
  63.     foreach($aOrder as $iCol{
  64.         $aWidth[$iColround( (100 $iTotalWidth$aWidth[$iCol0);
  65.         $iCheckTotalWidth += $aWidth[$iCol];
  66.     }
  67.     if ($iCheckTotalWidth 100// correction needed
  68.        $iCol array_search(max($aWidth),$aWidth);
  69.        $aWidth[$iCol-= $iCheckTotalWidth-100;
  70.     }
  71.     return $aWidth;
  72. }
  73.  
  74.  
  75. /**
  76.  * Function to retrieve correct icon based on provided message flags.  This is
  77.  * a merge/replacement for getFlagIcon() and getFlagText() functions.
  78.  * 
  79.  * @param array $aFlags associative array with seen,deleted,anwered and flag keys.
  80.  * @param string $icon_theme_path path to user's currently selected icon theme.
  81.  * @return string $icon full HTML img tag or text icon, depending on of user prefs
  82.  * @author Steve Brown
  83.  */
  84. function getFlagIcon ($aFlags$icon_theme_path{
  85.     /**
  86.      * 0  = unseen
  87.      * 1  = seen
  88.      * 2  = deleted
  89.      * 3  = deleted seen
  90.      * 4  = answered
  91.      * 5  = answered seen
  92.      * 6  = answered deleted
  93.      * 7  = answered deleted seen
  94.      * 8  = flagged
  95.      * 9  = flagged seen
  96.      * 10 = flagged deleted
  97.      * 11 = flagged deleted seen
  98.      * 12 = flagged answered
  99.      * 13 = flagged aswered seen
  100.      * 14 = flagged answered deleted
  101.      * 15 = flagged anserwed deleted seen
  102.      * ...
  103.      * 32 = forwarded
  104.      * 33 = forwarded seen
  105.      * 34 = forwarded deleted
  106.      * 35 = forwarded deleted seen
  107.      * ...
  108.      * 41 = flagged forwarded seen
  109.      * 42 = flagged forwarded deleted
  110.      * 43 = flagged forwarded deleted seen
  111.      */
  112.  
  113.     /**
  114.      * Use static vars to avoid initialisation of the array on each displayed row
  115.      */
  116.     global $nbsp;
  117.     static $flag_icons$flag_values;
  118.     if (!isset($flag_icons)) {
  119.         // This is by no means complete...
  120.         $flag_icons array (  
  121.         //      Image icon name                  Text Icon   Alt/Title Text
  122.         //      ---------------                  ---------   --------------
  123.         array ('msg_new.png',                    $nbsp,      '('._("New").')',
  124.         array ('msg_read.png',                   $nbsp,      '('._("Read").')'),
  125.         // i18n: "D" is short for "Deleted". Make sure that two icon strings aren't translated to the same character (only in 1.5).
  126.         array ('msg_new_deleted.png',            _("D"),     '('._("Deleted").')'),
  127.         array ('msg_read_deleted.png',           _("D"),     '('._("Deleted").')'),
  128.         // i18n: "A" is short for "Answered". Make sure that two icon strings aren't translated to the same character (only in 1.5).
  129.         array ('msg_new_reply.png',              _("A"),     '('._("Answered").')'),
  130.         array ('msg_read_reply.png',             _("A"),     '('._("Answered").')'),
  131.         array ('msg_new_deleted_reply.png',      _("D"),     '('._("Answered").')'),
  132.         array ('msg_read_deleted_reply.png',     _("D"),     '('._("Answered").')'),
  133.         // i18n: "F" is short for "Flagged". Make sure that two icon strings aren't translated to the same character (only in 1.5).
  134.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  135.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  136.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  137.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  138.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  139.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  140.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  141.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  142.         FALSE,
  143.         FALSE,
  144.         FALSE,
  145.         FALSE,
  146.         FALSE,
  147.         FALSE,
  148.         FALSE,
  149.         FALSE,
  150.         FALSE,
  151.         FALSE,
  152.         FALSE,
  153.         FALSE,
  154.         FALSE,
  155.         FALSE,
  156.         FALSE,
  157.         FALSE,
  158.         // i18n: "O" is short for "Forwarded". Make sure that two icon strings aren't translated to the same character (only in 1.5).
  159.         array ('msg_new_forwarded.png',          _("O"),     '('._("Forwarded").')'),
  160.         array ('msg_read_forwarded.png',         _("O"),     '('._("Forwarded").')'),
  161.         array ('msg_new_deleted_forwarded.png',  _("D"),     '('._("Forwarded").')'),
  162.         array ('msg_read_deleted_forwarded.png'_("D"),     '('._("Forwarded").')'),
  163.         FALSE,
  164.         FALSE,
  165.         FALSE,
  166.         FALSE,
  167.         FALSE,
  168.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  169.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  170.         array ('flagged.png',                    _("F"),     '('._("Flagged").')'),
  171.         );
  172.         
  173.         $flag_values array('seen'      => 1,
  174.                              'deleted'   => 2,
  175.                              'answered'  => 4,
  176.                              'flagged'   => 8,
  177.                              'draft'     => 16,
  178.                              'forwarded' => 32);
  179.     }
  180.  
  181.     /**
  182.      * The flags entry contain all items displayed in the flag column.
  183.      */
  184.     $icon '';
  185.  
  186.     $index 0;
  187.     foreach ($aFlags as $flag => $flagvalue{
  188.          switch ($flag{
  189.             case 'deleted':
  190.             case 'answered':
  191.             case 'forwarded':
  192.             case 'seen':
  193.             case 'flagged'if ($flagvalue$index += $flag_values[$flag]break;
  194.             defaultbreak;
  195.         }
  196.     }
  197.     
  198.     if (!empty($flag_icons[$index])) {
  199.         $data $flag_icons[$index];
  200.     else {
  201. //FIXME: previously this default was set to the last value of the $flag_icons array (when it was index 15 - flagged anserwed deleted seen) but I don't understand why... am changing it to flagged (index 15 just shows (only) the flag icon anyway)
  202.         $data $flag_icons[8]// default to just flagged
  203.     }
  204.  
  205.     $icon getIcon($icon_theme_path$data[0]$data[1]$data[2]);
  206.     return $icon;
  207. }
  208.  
  209.  
  210. /**
  211.  * Function to retrieve correct priority icon based on user prefs
  212.  * 
  213.  * @param integer $priority priority value of message
  214.  * @param string $icon_theme_path path to user's currently selected icon theme.
  215.  * @return string $icon full HTML img tag or text icon, depending on of user prefs
  216.  * @author Steve Brown
  217.  */
  218. function getPriorityIcon ($priority$icon_theme_path{
  219.     $icon '';
  220.  
  221.     switch ($priority{
  222.         case 1:
  223.         case 2:
  224.             $icon getIcon($icon_theme_path'prio_high.png'create_span('!''high_priority')_("High priority"));
  225.             break;
  226.         case 5:
  227.             $icon getIcon($icon_theme_path'prio_low.png'create_span('&#8595;''low_priority')_("Low priority"));
  228.             break;
  229.         default:
  230.             $icon getIcon($icon_theme_path'transparent.png'''_("Normal priority")5);
  231.             break;
  232.     }
  233.  
  234.     return $icon;
  235. }
  236.  
  237.  
  238. /**
  239.  * Function to retrieve correct attchment icon based on user prefs
  240.  * 
  241.  * @param boolean $attach TRUE if the message has an attachment
  242.  * @param string $icon_theme_path path to user's currently selected icon theme.
  243.  * @return string $icon full HTML img tag or text icon, depending on of user prefs
  244.  * @author Steve Brown
  245.  */
  246. function getAttachmentIcon ($attach$icon_theme_path{
  247.     $icon '';
  248.     
  249.     $icon_file $attach 'attach.png' 'transparent.png';
  250.     $alt_text $attach _("Attachment"_("No attachment");
  251.     $text $attach '+' '';
  252.     $icon getIcon($icon_theme_path$icon_file$text$alt_text);
  253.  
  254.     return $icon;
  255. }

Documentation generated on Mon, 13 Jan 2020 04:23:06 +0100 by phpDocumentor 1.4.3