• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cypht-org / cypht / 18977600044

31 Oct 2025 03:40PM UTC coverage: 79.595% (-0.02%) from 79.615%
18977600044

push

travis-ci

web-flow
Merge pull request #1767 from IrAlfred/fix-typos

fix(other): fix typo in various files

4798 of 6028 relevant lines covered (79.6%)

17.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.56
/modules/core/message_list_functions.php
1
<?php
2

3
/**
4
 * Core modules
5
 * @package modules
6
 * @subpackage core
7
 */
8

9
/**
10
 * get basic message list settings
11
 * @subpackage core/functions
12
 * @param string $path message list path
13
 * @param object $handler hm handler module
14
 * @return array
15
 */
16
if (!hm_exists('get_message_list_settings')) {
187✔
17
function get_message_list_settings($path, $handler) {
18
    $list_path = $path;
2✔
19
    $mailbox_list_title = array();
2✔
20
    $message_list_since = DEFAULT_SINCE;
2✔
21
    $per_source_limit = DEFAULT_PER_SOURCE;
2✔
22

23
    if ($path == 'unread') {
2✔
24
        $list_path = 'unread';
2✔
25
        $mailbox_list_title = array('Unread');
2✔
26
        $message_list_since = $handler->user_config->get('unread_since_setting', DEFAULT_UNREAD_SINCE);
2✔
27
        $per_source_limit = $handler->user_config->get('unread_per_source_setting', DEFAULT_UNREAD_PER_SOURCE);
2✔
28
    }
29
    elseif ($path == 'email') {
1✔
30
        $message_list_since = $handler->user_config->get('all_email_since_setting', DEFAULT_ALL_EMAIL_SINCE);
1✔
31
        $per_source_limit = $handler->user_config->get('all_email_per_source_setting', DEFAULT_ALL_EMAIL_PER_SOURCE);
1✔
32
        $list_path = 'email';
1✔
33
        $mailbox_list_title = array('All Email');
1✔
34
    }
35
    elseif ($path == 'flagged') {
1✔
36
        $list_path = 'flagged';
1✔
37
        $message_list_since = $handler->user_config->get('flagged_since_setting', DEFAULT_FLAGGED_SINCE);
1✔
38
        $per_source_limit = $handler->user_config->get('flagged_per_source_setting', DEFAULT_FLAGGED_PER_SOURCE);
1✔
39
        $mailbox_list_title = array('Flagged');
1✔
40
    }
41
    elseif ($path == 'combined_inbox') {
1✔
42
        $list_path = 'combined_inbox';
1✔
43
        $message_list_since = $handler->user_config->get('all_since_setting', DEFAULT_ALL_SINCE);
1✔
44
        $per_source_limit = $handler->user_config->get('all_per_source_setting', DEFAULT_ALL_PER_SOURCE);
1✔
45
        $mailbox_list_title = array('Everything');
1✔
46
    }
47
    elseif ($path == 'junk') {
1✔
48
        $list_path = 'junk';
×
49
        $message_list_since = $handler->user_config->get('junk_since_setting', DEFAULT_JUNK_SINCE);
×
50
        $per_source_limit = $handler->user_config->get('junk_per_source_setting', DEFAULT_JUNK_PER_SOURCE);
×
51
        $mailbox_list_title = array('Junk');
×
52
    }
53
    elseif ($path == 'snoozed') {
1✔
54
        $list_path = 'snoozed';
×
55
        $message_list_since = $handler->user_config->get('snoozed_since_setting', DEFAULT_SNOOZED_SINCE);
×
56
        $per_source_limit = $handler->user_config->get('snoozed_per_source_setting', DEFAULT_SNOOZED_PER_SOURCE);
×
57
        $mailbox_list_title = array('Snoozed');
×
58
    }
59
    elseif ($path == 'trash') {
1✔
60
        $list_path = 'trash';
×
61
        $message_list_since = $handler->user_config->get('trash_since_setting', DEFAULT_TRASH_SINCE);
×
62
        $per_source_limit = $handler->user_config->get('trash_per_source_setting', DEFAULT_TRASH_PER_SOURCE);
×
63
        $mailbox_list_title = array('Trash');
×
64
    }
65
    elseif ($path == 'sent') {
1✔
66
        $list_path = 'sent';
×
67
        $message_list_since = $handler->user_config->get('sent_since_setting', DEFAULT_SENT_SINCE);
×
68
        $per_source_limit = $handler->user_config->get('sent_per_source_setting', DEFAULT_SENT_PER_SOURCE);
×
69
        $mailbox_list_title = array('Sent');
×
70
    }
71
    elseif ($path == 'drafts') {
1✔
72
        $list_path = 'drafts';
×
73
        $message_list_since = $handler->user_config->get('drafts_since_setting', DEFAULT_DRAFT_SINCE);
×
74
        $per_source_limit = $handler->user_config->get('drafts_per_source_setting', DEFAULT_DRAFT_PER_SOURCE);
×
75
        $mailbox_list_title = array('Drafts');
×
76
    }
77
    elseif ($path == 'tag' && $handler->module_is_supported('tags')) {
1✔
78
        $list_path = 'tag';
×
79
        $message_list_since = $handler->user_config->get('tag_since_setting', DEFAULT_TAGS_SINCE);
×
80
        $per_source_limit = $handler->user_config->get('tag_per_source_setting', DEFAULT_TAGS_PER_SOURCE);
×
81
        $mailbox_list_title = array('Tag');
×
82
    }
83
    return array($list_path, $mailbox_list_title, $message_list_since, $per_source_limit);
2✔
84
}}
85

86
/**
87
 * Build meta information for a message list
88
 * @subpackage core/functions
89
 * @param array $input module output
90
 * @param object $output_mod Hm_Output_Module
91
 * @return string
92
 */
93
if (!hm_exists('message_list_meta')) {
187✔
94
function message_list_meta($input, $output_mod) {
95
    if (!array_key_exists('list_meta', $input) || !$input['list_meta']) {
2✔
96
        return '';
2✔
97
    }
98
    $limit = 0;
1✔
99
    $since = false;
1✔
100
    $times = array(
1✔
101
        'today' => 'Today',
1✔
102
        '-1 week' => 'Last 7 days',
1✔
103
        '-2 weeks' => 'Last 2 weeks',
1✔
104
        '-4 weeks' => 'Last 4 weeks',
1✔
105
        '-6 weeks' => 'Last 6 weeks',
1✔
106
        '-6 months' => 'Last 6 months',
1✔
107
        '-1 year' => 'Last year',
1✔
108
        '-5 years' => 'Last 5 years'
1✔
109
    );
1✔
110
    if (array_key_exists('per_source_limit', $input)) {
1✔
111
        $limit = $input['per_source_limit'];
1✔
112
    }
113
    if (!$limit) {
1✔
114
        $limit = DEFAULT_PER_SOURCE;
1✔
115
    }
116
    if (array_key_exists('message_list_since', $input)) {
1✔
117
        $since = $input['message_list_since'];
1✔
118
    }
119
    if (!$since) {
1✔
120
        $since = DEFAULT_SINCE;
1✔
121
    }
122
    $date = sprintf('%s', mb_strtolower($output_mod->trans($times[$since])));
1✔
123
    $max = sprintf($output_mod->trans('%d items per source'), $limit);
1✔
124
    $sources = '<span class="src_count">0</span>&nbsp;' . $output_mod->trans('sources');
1✔
125
    $total = '<span class="total">0</span>&nbsp;' .$output_mod->trans('total');
1✔
126

127
    return '<div class="list_meta d-flex align-items-center fs-6 text-nowrap me-auto mb-2 mb-md-0">'.$date.':&nbsp;'.$sources.',&nbsp;'.$max.',&nbsp;'.$total.'</div>';
1✔
128
}}
129

130
/**
131
 * Build sort dialog for a combined list
132
 * @subpackage core/functions
133
 * @param object $output_mod Hm_Output_Module
134
 * @return string
135
 */
136
if (!hm_exists('combined_sort_dialog')) {
187✔
137
function combined_sort_dialog($mod) {
138
    $sorts = [
2✔
139
        'arrival' => $mod->trans('Arrival Date'),
2✔
140
        'date' => $mod->trans('Sent Date'),
2✔
141
        'from' => $mod->trans('From'),
2✔
142
        'to' => $mod->trans('To'),
2✔
143
        'subject' => $mod->trans('Subject')
2✔
144
    ];
2✔
145

146
    $res = '<select name="sort" style="width: 150px" class="combined_sort form-select form-select-sm ms-2">';
2✔
147
    foreach ($sorts as $name => $val) {
2✔
148
        $res .= '<option value="'.$name.'"'.($mod->get('list_sort') == $name ? ' selected' : '').'>'.$val.' &darr;</option>';
2✔
149
        $res .= '<option value="-'.$name.'"'.($mod->get('list_sort') == '-'.$name ? ' selected' : '').'>'.$val.' &uarr;</option>';
2✔
150
    }
151
    $res .= '</select>';
2✔
152
    return $res;
2✔
153
}}
154

155
/**
156
 * Build a human readable interval string
157
 * @subpackage core/functions
158
 * @param string $date_str date string parsable by strtotime()
159
 * @return string
160
 */
161
if (!hm_exists('human_readable_interval')) {
187✔
162
function human_readable_interval($date_str) {
163
    if (!$date_str) {
2✔
164
        return 'Unknown';
1✔
165
    }
166
    $precision     = 2;
2✔
167
    $interval_time = array();
2✔
168
    $date          = strtotime($date_str);
2✔
169
    $interval      = time() - $date;
2✔
170
    $res           = array();
2✔
171

172
    $t['second'] = 1;
2✔
173
    $t['minute'] = $t['second']*60;
2✔
174
    $t['hour']   = $t['minute']*60;
2✔
175
    $t['day']    = $t['hour']*24;
2✔
176
    $t['week']   = $t['day']*7;
2✔
177
    $t['month']  = $t['day']*30;
2✔
178
    $t['year']   = $t['week']*52;
2✔
179

180
    if ($interval < -300) {
2✔
181
        return 'From the future!';
1✔
182
    }
183
    elseif ($interval <= 0) {
2✔
184
        return 'Just now';
2✔
185
    }
186
    foreach (array_reverse($t) as $name => $val) {
1✔
187
        if ($interval_time[$name] = ($interval/$val > 0) ? floor($interval/$val) : false) {
1✔
188
            $interval -= $val*$interval_time[$name];
1✔
189
        }
190
    }
191
    $interval_time = array_slice(array_filter($interval_time, function($v) { return $v > 0; }), 0, $precision);
1✔
192
    foreach($interval_time as $name => $val) {
1✔
193
        if ($val > 1) {
1✔
194
            $res[] = sprintf('%d %ss', $val, $name);
1✔
195
        }
196
        else {
197
            $res[] = sprintf('%d %s', $val, $name);
1✔
198
        }
199
    }
200
    return implode(', ', $res);
1✔
201
}}
202

203
/**
204
 * Output a message list row of data using callbacks
205
 * @subpackage core/functions
206
 * @param array $values data and callbacks for each cell
207
 * @param string $id unique id for the message
208
 * @param string $style message list style (news or email)
209
 * @param object $output_mod Hm_Output_Module
210
 * @param string $row_class optional table row css class
211
 * @return array
212
 */
213
if (!hm_exists('message_list_row')) {
187✔
214
function message_list_row($values, $id, $style, $output_mod, $row_class='', $msgId = '', $inReplyTo = '') {
215
    $res = '<tr class="'.$output_mod->html_safe($id);
1✔
216
    if ($row_class) {
1✔
217
        $res .= ' '.$output_mod->html_safe($row_class);
1✔
218
    }
219
    if (!empty($msgId)) {
1✔
220
        $res .= '" data-msg-id="'.$output_mod->html_safe($msgId);
×
221
    }
222
    if (!empty($inReplyTo)) {
1✔
223
        $res .= '" data-in-reply-to="'.$output_mod->html_safe($inReplyTo);
×
224
    }
225
    $data_uid = "";
1✔
226
    if ($uids = explode("_", $id)) {
1✔
227
        if (isset($uids[2])) {
1✔
228
            $data_uid = 'data-uid="'. $uids[2] .'"';
×
229
        }
230
    }
231
    if (!empty($data_uid)) {
1✔
232
        $res .= '" '.$data_uid.'>';
×
233
    } else {
234
        $res .= '">';
1✔
235
    }
236
    
237
    if ($style == 'news') {
1✔
238
        $res .= '<td class="news_cell checkbox_cell">';
1✔
239
    }
240
    foreach ($values as $vals) {
1✔
241
        if (function_exists($vals[0])) {
1✔
242
            $function = array_shift($vals);
1✔
243
            $res .= $function($vals, $style, $output_mod);
1✔
244
        }
245
    }
246
    if ($style == 'news') {
1✔
247
        $res .= '</td>';
1✔
248
    }
249
    $res .= '</tr>';
1✔
250
    return array($res, $id);
1✔
251
}}
252

253
/**
254
 * Generic callback for a message list table cell
255
 * @subpackage core/functions
256
 * @param array $vals data for the cell
257
 * @param string $style message list style
258
 * @param object $output_mod Hm_Output_Module
259
 * @return string
260
 */
261
if (!hm_exists('safe_output_callback')) {
187✔
262
function safe_output_callback($vals, $style, $output_mod) {
263
    $img = '';
1✔
264
    $title = '';
1✔
265
    if (count($vals) > 2) {
1✔
266
        if ($vals[2]){
1✔
267
            $img = '<i class="bi bi-filetype-'.$vals[2].'"></i>';
1✔
268
        }
269
        if (count($vals) > 3) {
1✔
270
            $title = $output_mod->html_safe($vals[3]);
×
271
        } else {
272
            $title = $output_mod->html_safe($vals[1]);
1✔
273
        }
274
    }
275
    if ($style == 'news') {
1✔
276
        return sprintf('<div class="%s" data-title="%s">%s%s</div>', $output_mod->html_safe($vals[0]), $title, $img, $output_mod->html_safe($vals[1]));
1✔
277
    }
278
    return sprintf('<td class="%s" data-title="%s">%s%s</td>', $output_mod->html_safe($vals[0]), $title, $img, $output_mod->html_safe($vals[1]));
1✔
279
}}
280

281
/**
282
 * Callback for a message list checkbox
283
 * @subpackage core/functions
284
 * @param array $vals data for the cell
285
 * @param string $style message list style
286
 * @param object $output_mod Hm_Output_Module
287
 * @return string
288
 */
289
if (!hm_exists('checkbox_callback')) {
187✔
290
function checkbox_callback($vals, $style, $output_mod) {
291
    if ($style == 'news') {
1✔
292
        return sprintf('<input type="checkbox" id="%s" value="%s" />'.
1✔
293
            '<label class="checkbox_label" for="%s"></label>'.
1✔
294
            '</td><td class="news_cell">', $output_mod->html_safe($vals[0]),
1✔
295
            $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[0]));
1✔
296
    }
297
    return sprintf('<td class="checkbox_cell">'.
1✔
298
        '<input id="'.$output_mod->html_safe($vals[0]).'" type="checkbox" value="%s" />'.
1✔
299
        '<label class="checkbox_label" for="'.$output_mod->html_safe($vals[0]).'"></label>'.
1✔
300
        '</td>', $output_mod->html_safe($vals[0]));
1✔
301
}}
302

303
/**
304
 * Callback for a subject cell in a message list
305
 * @subpackage core/functions
306
 * @param array $vals data for the cell
307
 * @param string $style message list style
308
 * @param object $output_mod Hm_Output_Module
309
 * @return string
310
 */
311
if (!hm_exists('subject_callback')) {
187✔
312
function subject_callback($vals, $style, $output_mod) {
313
    $img = '';
1✔
314
    $subject = '';
1✔
315
    $preview_msg = '';
1✔
316
    $icon_type_msg = '';
1✔
317
    if (isset($vals[3]) && $vals[3]) {
1✔
318
        $img = '<i class="bi bi-filetype-'.$vals[3].'"></i>';
1✔
319
    }
320
    $subject = $output_mod->html_safe($vals[0]);
1✔
321
    if (isset($vals[4]) && $vals[4]) {
1✔
322
        $lines = explode("\n", $vals[4]);
×
323
        $clean = array_filter(array_map('trim', $lines), function ($line) {
×
324
            return $line !== ''
×
325
                && stripos($line, 'boundary=') === false
×
326
                && !preg_match('/^-{2,}==/', $line)
×
327
                && stripos($line, 'content-type:') !== 0
×
328
                && stripos($line, 'charset=') === false
×
329
                && stripos($line, 'content-transfer-encoding:') !== 0;
×
330
        });
×
331
        $clean_text = implode("\n", $clean);
×
332
        $preview_msg = $output_mod->html_safe($clean_text);
×
333
    }
334

335
    if (isset($vals[5]) && $vals[5]) {
1✔
336
        if ($vals[5] == 'calendar') {
×
337
            $icon_type_msg = '<span class="bi bi-calendar4-event"></span>';
×
338
        }
339
    }
340
    
341
    $hl_subject = preg_replace("/^(\[[^\]]+\])/", '<span class="s_pre">$1</span>', $subject);
1✔
342
    if ($style == 'news') {
1✔
343
        if ($output_mod->get('is_mobile')) {
1✔
344
            return sprintf('<div class="subject"><div class="%s" title="%s">%s %s <a href="%s">%s</a></div></div>', $output_mod->html_safe(implode(' ', $vals[2])), $subject, $img, $icon_type_msg, $output_mod->html_safe($vals[1]), $hl_subject);
×
345
        }
346
        return sprintf('<div class="subject"><div class="%s" title="%s">%s %s <a href="%s">%s</a><p class="fw-light">%s</p></div></div>', $output_mod->html_safe(implode(' ', $vals[2])), $subject, $icon_type_msg, $img, $output_mod->html_safe($vals[1]), $hl_subject, $preview_msg);
1✔
347
    }
348

349
    if ($output_mod->get('is_mobile')) {
1✔
350
        return sprintf('<td class="subject"><div class="%s"> %s <a title="%s" href="%s">%s</a></div></td>', $output_mod->html_safe(implode(' ', $vals[2])), $icon_type_msg, $subject, $output_mod->html_safe($vals[1]), $hl_subject);
×
351
    }
352
    return sprintf('<td class="subject"><div class="%s"> %s <a title="%s" href="%s">%s</a><p class="fw-light">%s</p></div></td>', $output_mod->html_safe(implode(' ', $vals[2])), $icon_type_msg, $subject, $output_mod->html_safe($vals[1]), $hl_subject, $preview_msg);
1✔
353
}}
354

355
/**
356
 * Callback for a date cell in a message list
357
 * @subpackage core/functions
358
 * @param array $vals data for the cell
359
 * @param string $style message list style
360
 * @param object $output_mod Hm_Output_Module
361
 * @return string
362
 */
363
if (!hm_exists('date_callback')) {
187✔
364
function date_callback($vals, $style, $output_mod) {
365
    $delayed_class = isset($vals[2]) && $vals[2]? ' delayed_date': '';
1✔
366
    if ($style == 'news') {
1✔
367
        return sprintf('<div class="msg_date%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></div>', $delayed_class, $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
1✔
368
    }
369
    return sprintf('<td class="msg_date%s" title="%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></td>', $delayed_class, $output_mod->html_safe(date('r', $vals[1])), $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
1✔
370
}}
371

372
function dates_holders_callback($vals) {
373
    $res = '<td class="dates d-none">';
×
374
    $res .= '<input type="hidden" name="arrival" class="arrival" value="'. $vals[0] .'" arial-label="Arrival date" />';
×
375
    $res .= '<input type="hidden" name="date" class="date" value="'. $vals[1] .'" arial-label="Sent date" />';
×
376
    $res .= '</td>';
×
377
    return $res;
×
378
}
379

380
/**
381
 * Callback for an icon in a message list row
382
 * @subpackage core/functions
383
 * @param array $vals data for the cell
384
 * @param string $style message list style
385
 * @param object $output_mod Hm_Output_Module
386
 * @return string
387
 */
388
if (!hm_exists('icon_callback')) {
187✔
389
function icon_callback($vals, $style, $output_mod) {
390
    $icons = '';
1✔
391
    $title = array();
1✔
392
    $show_icons = $output_mod->get('msg_list_icons');
1✔
393
    if (in_array('flagged', $vals[0])) {
1✔
394
        $icons .= $show_icons ? '<i class="bi bi-star-half"></i>' : ' F';
1✔
395
        $title[] = $output_mod->trans('Flagged');
1✔
396
    }
397
    if (in_array('draft', $vals[0])) {
1✔
398
        $icons .= $show_icons ? '<i class="bi bi-star-half"></i>' : ' D';
×
399
        $title[] = $output_mod->trans('Draft');
×
400
    }
401
    if (in_array('answered', $vals[0])) {
1✔
402
        $icons .= $show_icons ? '<i class="bi bi-check-circle-fill"></i>' : ' A';
1✔
403
        $title[] = $output_mod->trans('Answered');
1✔
404
    }
405
    if (in_array('attachment', $vals[0])) {
1✔
406
        $icons .= $show_icons ? '<i class="bi bi-paperclip"></i>' : ' <i class="bi bi-plus-circle"></i>';
1✔
407
        $title[] = $output_mod->trans('Attachment');
1✔
408
    }
409
    $title = implode(', ', $title);
1✔
410
    if ($style == 'news') {
1✔
411
        return sprintf('<div class="icon" title="%s">%s</div>', $title, $icons);
1✔
412
    }
413
    return sprintf('<td class="icon" title="%s">%s</td>', $title, $icons);
1✔
414
}}
415

416
/**
417
 * Output message controls
418
 * @subpackage core/functions
419
 * @param object $output_mod Hm_Output_Module
420
 * @return string
421
 */
422
if (!hm_exists('message_controls')) {
187✔
423
function message_controls($output_mod) {
424
    $txt = '';
3✔
425
    $controls = ['read', 'unread', 'flag', 'unflag', 'delete', 'archive', 'junk'];
3✔
426
    $controls = array_filter($controls, function($val) use ($output_mod) {
3✔
427
        if (in_array($val, [$output_mod->get('list_path', ''), strtolower($output_mod->get('core_msg_control_folder', ''))])) {
3✔
428
            return false;
×
429
        }
430
        if ($val == 'flag' && $output_mod->get('list_path', '') == 'flagged') {
3✔
431
            return false;
×
432
        }
433
        return true;
3✔
434
    });
3✔
435

436
    $res = '<a class="toggle_link" href="#"><i class="bi bi-check-square-fill"></i></a>'.
3✔
437
        '<div class="msg_controls fs-6 d-none gap-1 align-items-center">'.
3✔
438
            '<div class="dropdown on_mobile">'.
3✔
439
                '<button type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle" id="coreMsgControlDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Actions</button>'.
3✔
440
                '<ul class="dropdown-menu" aria-labelledby="coreMsgControlDropdown">';
3✔
441
    foreach ($controls as $control) {
3✔
442
        $res .= '<li><a class="dropdown-item msg_'.$control.' core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="'.$control.'">'.$output_mod->trans(ucfirst($control)).'</a></li>';
3✔
443
    }
444
    $res .= '</ul>'.
3✔
445
            '</div>';
3✔
446

447
    foreach ($controls as $control) {
3✔
448
        $res .= '<a class="msg_'.$control.' core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="'.$control.'">'.$output_mod->trans(ucfirst($control)).'</a>';
3✔
449
    }
450

451
    if ($output_mod->get('msg_controls_extra')) {
3✔
452
        $res .= $output_mod->get('msg_controls_extra');
1✔
453
    }
454
    if(!empty($output_mod->get('tags'))) {
3✔
455
        $res .= tags_dropdown($output_mod, []);
×
456
    }
457
    $res .= '</div>';
3✔
458
    return $res;
3✔
459
}}
460

461
/**
462
 * Output select element for "received since" options
463
 * @subpackage core/functions
464
 * @param string $since current value to pre-select
465
 * @param string $name name used as the elements id and name
466
 * @param object $output_mod Hm_Output_Module
467
 * @return string
468
 */
469
if (!hm_exists('message_since_dropdown')) {
187✔
470
function message_since_dropdown($since, $name, $output_mod, $original_default_value = '-1 week') {
471
    $times = array(
9✔
472
        'today' => 'Today',
9✔
473
        '-1 week' => 'Last 7 days',
9✔
474
        '-2 weeks' => 'Last 2 weeks',
9✔
475
        '-4 weeks' => 'Last 4 weeks',
9✔
476
        '-6 weeks' => 'Last 6 weeks',
9✔
477
        '-6 months' => 'Last 6 months',
9✔
478
        '-1 year' => 'Last year',
9✔
479
        '-5 years' => 'Last 5 years'
9✔
480
    );
9✔
481
    $res = '<select name="'.$name.'" id="'.$name.'" class="message_list_since form-select form-select-sm" data-default-value="'.$original_default_value.'">';
9✔
482
    $reset = '';
9✔
483
    foreach ($times as $val => $label) {
9✔
484
        $res .= '<option';
9✔
485
        if ($val == $since) {
9✔
486
            $res .= ' selected="selected"';
9✔
487
            if ($val != $original_default_value) {
9✔
488
                $reset = '<span class="tooltip_restore" restore_aria_label="Restore default value"><i class="bi bi-arrow-counterclockwise refresh_list reset_default_value_select"></i></span>';
7✔
489
            }
490

491
        }
492
        $res .= ' value="'.$val.'">'.$output_mod->trans($label).'</option>';
9✔
493
    }
494
    $res .= '</select>'.$reset;
9✔
495
    return $res;
9✔
496
}}
497

498
/**
499
 * Output a source list for a message list
500
 * @subpackage core/functions
501
 * @param array $sources source of the list
502
 * @param object $output_mod Hm_Output_Module
503
 */
504
if (!hm_exists('list_sources')) {
187✔
505
function list_sources($sources, $output_mod) {
506
    $res = '<div class="list_sources w-100 mt-2">';
3✔
507
    $res .= '<div class="src_title fs-5 mb-2">'.$output_mod->html_safe('Sources').'</div>';
3✔
508
    foreach ($sources as $src) {
3✔
509
        if (array_key_exists('group', $src) && $src['group'] == 'background') {
1✔
510
            continue;
1✔
511
        }
512
        if (array_key_exists('nodisplay', $src) && $src['nodisplay']) {
1✔
513
            continue;
×
514
        }
515
        if ($src['type'] == 'imap' && !array_key_exists('folder_name', $src)) {
1✔
516
            $folder = 'INBOX';
1✔
517
        }
518
        elseif (!array_key_exists('folder_name', $src)) {
1✔
519
            $folder = '';
×
520
        }
521
        else {
522
            $folder = $src['folder_name'];
1✔
523
        }
524
        $res .= '<div class="list_src">'.$output_mod->html_safe($src['type']).' '.$output_mod->html_safe($src['name']);
1✔
525
        $res .= ' '.$output_mod->html_safe($folder);
1✔
526
        $res .= '</div>';
1✔
527
    }
528
    $res .= '</div>';
3✔
529
    return $res;
3✔
530
}}
531

532

533

534
/**
535
 * Output a source list for a message list
536
 * @subpackage core/functions
537
 * @param array $sources source of the list
538
 * @param object $output_mod Hm_Output_Module
539
 */
540
if (!hm_exists('update_search_label_field')) {
187✔
541
function update_search_label_field($search_term, $output_mod) {
542
    $res = '<div class="update_search_label_field">';
×
543
    $res .= '<div class="update_saved_search_title">'.$output_mod->html_safe('Update saved search label') .'</div>';
×
544
    $res .= '<div>
×
545
    <input type="hidden" name="page" value="search">
546
    <input type="hidden" name="search_terms" value="'. $search_term .'">
×
547
    <label class="screen_reader" for="search_terms_label">Current Search Label</label>
548
    <input required="" disabled id="old_search_terms_label" type="search" value="' . $search_term . '" class="old_search_terms_label form-control form-control-sm" name="old_search_terms_label">
×
549
    <label class="screen_reader" for="search_terms_label">New Search Terms</label>
550
    <input required="" placeholder="New search terms label" id="search_terms_label" type="search" class="search_terms_label form-control form-control-sm" name="search_terms_label">
551
    <div>
552
        <input type="button" class="search_label_update btn w-100 btn-primary btn-sm" value="Update">
553
    </div>
554
    </div>';
×
555
    $res .= '</div>';
×
556
    return $res;
×
557
}}
558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577
/**
578
 * Output message list controls
579
 * @subpackage core/functions
580
 * @param string $refresh_link refresh link tag
581
 * @param string $config_link configuration link tag
582
 * @param string $source_link source link tag
583
 * @return string
584
 */
585
if (!hm_exists('list_controls')) {
187✔
586
function list_controls($refresh_link, $config_link, $source_link = false, $search_field = '') {
587
    return '<div class="list_controls no_mobile d-flex gap-3 align-items-center">' .
3✔
588
                $refresh_link . $source_link . $config_link . $search_field .
3✔
589
           '</div>' .
3✔
590
           '<div class="list_controls on_mobile">' .
3✔
591
                $search_field .
3✔
592
                '<i class="bi bi-filter-circle" onclick="listControlsMenu()"></i>' .
3✔
593
                '<div id="list_controls_menu" class="list_controls_menu">' .
3✔
594
                    $refresh_link . $source_link . $config_link .
3✔
595
                '</div>' .
3✔
596
           '</div>';
3✔
597
}}
598

599
/**
600
 * Validate search terms
601
 * @subpackage core/functions
602
 * @param string $terms search terms to validate
603
 * @return string
604
 */
605
if (!hm_exists('validate_search_terms')) {
187✔
606
function validate_search_terms($terms) {
607
    $terms = trim(strip_tags($terms));
2✔
608
    if (!$terms) {
2✔
609
        $terms = '';
1✔
610
    }
611
    return $terms;
2✔
612
}}
613

614
/**
615
 * Validate the name of a search field
616
 * @subpackage core/functions
617
 * @param string $fld name to validate
618
 * @return mixed
619
 */
620
if (!hm_exists('validate_search_fld')) {
187✔
621
function validate_search_fld($fld) {
622
    if (in_array($fld, array('TEXT', 'BODY', 'FROM', 'SUBJECT', 'TO', 'CC'))) {
2✔
623
        return $fld;
2✔
624
    }
625
    return false;
1✔
626
}}
627

628
/**
629
 * Output a select element for the search field
630
 * @subpackage core/functions
631
 * @param string $current currently selected field
632
 * @param object $output_mod Hm_Output_Module
633
 * @return string
634
 */
635
if (!hm_exists('search_field_selection')) {
187✔
636
function search_field_selection($current, $output_mod) {
637
    $flds = array(
2✔
638
        'TEXT' => 'Entire message',
2✔
639
        'BODY' => 'Message body',
2✔
640
        'SUBJECT' => 'Subject',
2✔
641
        'FROM' => 'From',
2✔
642
        'TO' => 'To',
2✔
643
        'CC' => 'Cc',
2✔
644
    );
2✔
645
    $res = '<select class="form-select form-select-sm" id="search_fld" name="search_fld">';
2✔
646
    foreach ($flds as $val => $name) {
2✔
647
        $res .= '<option ';
2✔
648
        if ($current == $val) {
2✔
649
            $res .= 'selected="selected" ';
2✔
650
        }
651
        $res .= 'value="'.$val.'">'.$output_mod->trans($name).'</option>';
2✔
652
    }
653
    $res .= '</select>';
2✔
654
    return $res;
2✔
655
}}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc