6 * Provides some functions for use in left_main.php and templates. Do not echo
7 * output from these functions!
9 * @copyright 1999-2020 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
13 * @subpackage templates
17 * Recursively iterates a mailboxes object to get the cummulative count of
18 * messages for all folderes below the current mailbox.
20 * @param object $boxes Object of the class mailboxes
21 * @param string $type Whether to fetch unseen only or all messages
25 function getMessageCount ($boxes, $type='total') {
29 // The Trash folder isn't counted...
30 if ($boxes->mailboxname_full
== $trash_folder)
34 if (strtolower($type) == 'unseen')
36 else $field = 'total';
39 $count +
= !empty($boxes->{$field}) ?
$boxes->{$field} : 0;
40 for ($j = 0; $j <count($boxes->mbxs
); $j++
) {
41 $count +
= getMessageCount($boxes->mbxs
[$j], $type);
48 * Recursively iterates a mailboxes object to build a data structure that is
49 * easy for template authors to work with.
50 FIXME: well.... why not document that data structure here?
52 * @param object $boxes Object of the class mailboxes
56 function getBoxStructure ($boxes) {
57 global $data_dir, $username, $icon_theme_path;
64 $mailbox = $boxes->mailboxname_full
;
65 $mailboxURL = urlencode($mailbox);
68 $box['MailboxFullName'] = $mailbox;
69 $box['MailboxName'] = $boxes->mailboxname_sub
;
70 $box['MessageCount'] = !empty($boxes->total
) ?
$boxes->total
: 0;
71 $box['UnreadCount'] = !empty($boxes->unseen
) ?
$boxes->unseen
: 0;
73 // Needed in case user enables cummulative message counts
74 $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total');
75 $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen');
77 $box['ViewLink'] = array( 'Target' => 'right',
78 'URL' => 'right_main.php?PG_SHOWALL=0&startMessage=1&mailbox='.$mailboxURL
81 $box['IsRecent'] = isset($boxes->recent
) && $boxes->recent
;
82 $box['IsSpecial'] = isset($boxes->is_special
) && $boxes->is_special
;
83 $box['IsRoot'] = isset($boxes->is_root
) && $boxes->is_root
;
84 $box['IsNoSelect'] = isset($boxes->is_noselect
) && $boxes->is_noselect
;
86 $box['IsInbox'] = isset($boxes->is_inbox
) && $boxes->is_inbox
;
87 $box['IsSent'] = isset($boxes->is_sent
) && $boxes->is_sent
;
88 $box['IsTrash'] = isset($boxes->is_trash
) && $boxes->is_trash
;
89 $box['IsDraft'] = isset($boxes->is_draft
) && $boxes->is_draft
;
90 $box['IsNoInferiors'] = isset($boxes->is_noinferiors
) && $boxes->is_noinferiors
;
92 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
93 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
94 $collapse = (int)$collapse == SM_BOX_COLLAPSED
;
95 $box['IsCollapsed'] = $collapse;
98 * Check for an image needed here. If the file exists in $icon_theme_path
99 * assume the template provides all icons. If not, we will use the
100 * SQM default images. If icons have been disabled, $icon_theme_path
104 $text_icon = $box['IsCollapsed'] ?
'+' : '-';
105 $icon_file = $box['IsCollapsed'] ?
'plus.png' : 'minus.png';
106 $icon_alt = $box['IsCollapsed'] ?
'Expand Box' : 'Collapse Box';
107 $icon = getIcon($icon_theme_path, $icon_file, $text_icon, $icon_alt);
109 $box['CollapseLink'] = array ( 'Target' => 'left',
110 'URL' => 'left_main.php?'.($box['IsCollapsed'] ?
'unfold' : 'fold') .'='.$mailboxURL,
111 'Icon' => $icon .' '
114 $box['ChildBoxes'] = array();
115 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
116 $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs
[$i]);
119 // if plugins want to add some text or link after the folder name in
120 // the folder list, they should add to the "ExtraOutput" array element
121 // in $box (remember, it's passed through the hook by reference) -- making
122 // sure to play nice with other plugins by *concatenating* to "ExtraOutput"
123 // and NOT by overwriting it
125 // known users of this hook:
128 do_hook('left_main_after_each_folder', $box);