message_list_util.php 8.9 KB

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