folder_list_util.php 4.1 KB

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