folder_list_util.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 1999-2025 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. FIXME: well.... why not document that data structure here?
  42. *
  43. * @param object $boxes Object of the class mailboxes
  44. * @author Steve Brown
  45. * @since 1.5.2
  46. */
  47. function getBoxStructure ($boxes) {
  48. global $data_dir, $username, $icon_theme_path;
  49. // Stop condition
  50. if (empty($boxes)) {
  51. return array();
  52. }
  53. $mailbox = $boxes->mailboxname_full;
  54. $mailboxURL = urlencode($mailbox);
  55. $box = array();
  56. $box['MailboxFullName'] = $mailbox;
  57. $box['MailboxName'] = $boxes->mailboxname_sub;
  58. $box['MessageCount'] = !empty($boxes->total) ? $boxes->total : 0;
  59. $box['UnreadCount'] = !empty($boxes->unseen) ? $boxes->unseen : 0;
  60. // Needed in case user enables cummulative message counts
  61. $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
  62. $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
  63. $box['ViewLink'] = array( 'Target' => 'right',
  64. 'URL' => 'right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox='.$mailboxURL
  65. );
  66. $box['IsRecent'] = isset($boxes->recent) && $boxes->recent;
  67. $box['IsSpecial'] = isset($boxes->is_special) && $boxes->is_special;
  68. $box['IsRoot'] = isset($boxes->is_root) && $boxes->is_root;
  69. $box['IsNoSelect'] = isset($boxes->is_noselect) && $boxes->is_noselect;
  70. $box['IsInbox'] = isset($boxes->is_inbox) && $boxes->is_inbox;
  71. $box['IsSent'] = isset($boxes->is_sent) && $boxes->is_sent;
  72. $box['IsTrash'] = isset($boxes->is_trash) && $boxes->is_trash;
  73. $box['IsDraft'] = isset($boxes->is_draft) && $boxes->is_draft;
  74. $box['IsNoInferiors'] = isset($boxes->is_noinferiors) && $boxes->is_noinferiors;
  75. $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
  76. $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
  77. $collapse = (int)$collapse == SM_BOX_COLLAPSED;
  78. $box['IsCollapsed'] = $collapse;
  79. /*
  80. * Check for an image needed here. If the file exists in $icon_theme_path
  81. * assume the template provides all icons. If not, we will use the
  82. * SQM default images. If icons have been disabled, $icon_theme_path
  83. * will be NULL.
  84. */
  85. $text_icon = $box['IsCollapsed'] ? '+' : '-';
  86. $icon_file = $box['IsCollapsed'] ? 'plus.png' : 'minus.png';
  87. $icon_alt = $box['IsCollapsed'] ? 'Expand Box' : 'Collapse Box';
  88. $icon = getIcon($icon_theme_path, $icon_file, $text_icon, $icon_alt);
  89. $box['CollapseLink'] = array ( 'Target' => 'left',
  90. 'URL' => 'left_main.php?'.($box['IsCollapsed'] ? 'unfold' : 'fold') .'='.$mailboxURL,
  91. 'Icon' => $icon .'&nbsp;'
  92. );
  93. $box['ChildBoxes'] = array();
  94. for ($i = 0; $i <count($boxes->mbxs); $i++) {
  95. $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs[$i]);
  96. }
  97. // if plugins want to add some text or link after the folder name in
  98. // the folder list, they should add to the "ExtraOutput" array element
  99. // in $box (remember, it's passed through the hook by reference) -- making
  100. // sure to play nice with other plugins by *concatenating* to "ExtraOutput"
  101. // and NOT by overwriting it
  102. //
  103. // known users of this hook:
  104. // empty_folders
  105. //
  106. do_hook('left_main_after_each_folder', $box);
  107. return $box;
  108. }