29997535 |
1 | <?php |
a9cce2ae |
2 | |
29997535 |
3 | /** |
a9cce2ae |
4 | * folder_list_util.php |
29997535 |
5 | * |
6 | * Provides some functions for use in left_main.php and templates. Do not echo |
7 | * output from these functions! |
8 | * |
22387c8d |
9 | * @copyright 1999-2017 The SquirrelMail Project Team |
29997535 |
10 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
11 | * @version $Id$ |
12 | * @package squirrelmail |
13 | * @subpackage templates |
14 | */ |
15 | |
16 | /** |
17 | * Recursively iterates a mailboxes object to get the cummulative count of |
18 | * messages for all folderes below the current mailbox. |
19 | * |
20 | * @param object $boxes Object of the class mailboxes |
21 | * @param string $type Whether to fetch unseen only or all messages |
22 | * @author Steve Brown |
23 | * @since 1.5.2 |
24 | */ |
6d671aa1 |
25 | function getMessageCount ($boxes, $type='total') { |
bd116f83 |
26 | |
27 | global $trash_folder; |
28 | |
29997535 |
29 | // The Trash folder isn't counted... |
bd116f83 |
30 | if ($boxes->mailboxname_full == $trash_folder) |
29997535 |
31 | return 0; |
32 | |
33 | $count = 0; |
34 | if (strtolower($type) == 'unseen') |
35 | $field = 'unseen'; |
36 | else $field = 'total'; |
37 | |
38 | |
39 | $count += !empty($boxes->{$field}) ? $boxes->{$field} : 0; |
40 | for ($j = 0; $j <count($boxes->mbxs); $j++) { |
41 | $count += getMessageCount($boxes->mbxs[$j], $type); |
42 | } |
43 | |
44 | return $count; |
45 | } |
46 | |
47 | /** |
48 | * Recursively iterates a mailboxes object to build a data structure that is |
49 | * easy for template authors to work with. |
e883b46e |
50 | FIXME: well.... why not document that data structure here? |
29997535 |
51 | * |
52 | * @param object $boxes Object of the class mailboxes |
53 | * @author Steve Brown |
54 | * @since 1.5.2 |
55 | */ |
6d671aa1 |
56 | function getBoxStructure ($boxes) { |
29997535 |
57 | global $data_dir, $username, $icon_theme_path; |
58 | |
59 | // Stop condition |
60 | if (empty($boxes)) { |
61 | return array(); |
62 | } |
63 | |
64 | $mailbox = $boxes->mailboxname_full; |
65 | $mailboxURL = urlencode($mailbox); |
66 | $box = array(); |
67 | |
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; |
72 | |
73 | // Needed in case user enables cummulative message counts |
74 | $box['CummulativeMessageCount'] = getMessageCount($boxes, 'total'); |
75 | $box['CummulativeUnreadCount'] = getMessageCount($boxes, 'unseen'); |
76 | |
77 | $box['ViewLink'] = array( 'Target' => 'right', |
78 | 'URL' => 'right_main.php?PG_SHOWALL=0&startMessage=1&mailbox='.$mailboxURL |
79 | ); |
80 | |
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; |
85 | |
6d671aa1 |
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; |
91 | |
29997535 |
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; |
96 | |
97 | /* |
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 |
101 | * will be NULL. |
102 | */ |
103 | |
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); |
108 | |
109 | $box['CollapseLink'] = array ( 'Target' => 'left', |
110 | 'URL' => 'left_main.php?'.($box['IsCollapsed'] ? 'unfold' : 'fold') .'='.$mailboxURL, |
111 | 'Icon' => $icon .' ' |
112 | ); |
113 | |
114 | $box['ChildBoxes'] = array(); |
115 | for ($i = 0; $i <count($boxes->mbxs); $i++) { |
116 | $box['ChildBoxes'][] = getBoxStructure($boxes->mbxs[$i]); |
117 | } |
118 | |
e883b46e |
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 |
124 | // |
125 | // known users of this hook: |
126 | // empty_folders |
127 | // |
128 | do_hook('left_main_after_each_folder', $box); |
129 | |
29997535 |
130 | return $box; |
131 | } |