folder_list_util.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * folder_list_util.php
  4. *
  5. * Provides some functions for use in left_main.php and templates. Do not echo
  6. * output from these functions!
  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$
  11. * @package squirrelmail
  12. * @subpackage templates
  13. */
  14. /**
  15. * Recursively iterates a mailboxes object to get the cummulative count of
  16. * messages for all folderes below the current mailbox.
  17. *
  18. * @param object $boxes Object of the class mailboxes
  19. * @param string $type Whether to fetch unseen only or all messages
  20. * @author Steve Brown
  21. * @since 1.5.2
  22. */
  23. function getMessageCount ($boxes, $type='total') {
  24. global $trash_folder;
  25. // The Trash folder isn't counted...
  26. if ($boxes->mailboxname_full == $trash_folder)
  27. return 0;
  28. $count = 0;
  29. if (strtolower($type) == 'unseen')
  30. $field = 'unseen';
  31. else $field = 'total';
  32. $count += !empty($boxes->{$field}) ? $boxes->{$field} : 0;
  33. for ($j = 0; $j <count($boxes->mbxs); $j++) {
  34. $count += getMessageCount($boxes->mbxs[$j], $type);
  35. }
  36. return $count;
  37. }
  38. /**
  39. * Recursively iterates a mailboxes object to build a data structure that is
  40. * easy for template authors to work with.
  41. *
  42. * @param object $boxes Object of the class mailboxes
  43. * @author Steve Brown
  44. * @since 1.5.2
  45. */
  46. function getBoxStructure ($boxes) {
  47. global $data_dir, $username, $icon_theme_path;
  48. // Stop condition
  49. if (empty($boxes)) {
  50. return array();
  51. }
  52. $mailbox = $boxes->mailboxname_full;
  53. $mailboxURL = urlencode($mailbox);
  54. $box = array();
  55. $box['MailboxFullName'] = $mailbox;
  56. $box['MailboxName'] = $boxes->mailboxname_sub;
  57. $box['MessageCount'] = !empty($boxes->total) ? $boxes->total : 0;
  58. $box['UnreadCount'] = !empty($boxes->unseen) ? $boxes->unseen : 0;
  59. // Needed in case user enables cummulative message counts
  60. $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
  61. $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
  62. $box['ViewLink'] = array( 'Target' => 'right',
  63. 'URL' => 'right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox='.$mailboxURL
  64. );
  65. $box['IsRecent'] = isset($boxes->recent) && $boxes->recent;
  66. $box['IsSpecial'] = isset($boxes->is_special) && $boxes->is_special;
  67. $box['IsRoot'] = isset($boxes->is_root) && $boxes->is_root;
  68. $box['IsNoSelect'] = isset($boxes->is_noselect) && $boxes->is_noselect;
  69. $box['IsInbox'] = isset($boxes->is_inbox) && $boxes->is_inbox;
  70. $box['IsSent'] = isset($boxes->is_sent) && $boxes->is_sent;
  71. $box['IsTrash'] = isset($boxes->is_trash) && $boxes->is_trash;
  72. $box['IsDraft'] = isset($boxes->is_draft) && $boxes->is_draft;
  73. $box['IsNoInferiors'] = isset($boxes->is_noinferiors) && $boxes->is_noinferiors;
  74. $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
  75. $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
  76. $collapse = (int)$collapse == SM_BOX_COLLAPSED;
  77. $box['IsCollapsed'] = $collapse;
  78. /*
  79. * Check for an image needed here. If the file exists in $icon_theme_path
  80. * assume the template provides all icons. If not, we will use the
  81. * SQM default images. If icons have been disabled, $icon_theme_path
  82. * will be NULL.
  83. */
  84. $text_icon = $box['IsCollapsed'] ? '+' : '-';
  85. $icon_file = $box['IsCollapsed'] ? 'plus.png' : 'minus.png';
  86. $icon_alt = $box['IsCollapsed'] ? 'Expand Box' : 'Collapse Box';
  87. $icon = getIcon($icon_theme_path, $icon_file, $text_icon, $icon_alt);
  88. $box['CollapseLink'] = array ( 'Target' => 'left',
  89. 'URL' => 'left_main.php?'.($box['IsCollapsed'] ? 'unfold' : 'fold') .'='.$mailboxURL,
  90. 'Icon' => $icon .'&nbsp;'
  91. );
  92. $box['ChildBoxes'] = array();
  93. for ($i = 0; $i <count($boxes->mbxs); $i++) {
  94. $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs[$i]);
  95. }
  96. return $box;
  97. }