Skip to content

Commit 9ad1d59

Browse files
committed
feat(backend): refactor code based on review feedback
Fixed typo with double 'p'. Used switch statement in 'get_scheduled_date' and other
1 parent 4ad32cc commit 9ad1d59

File tree

4 files changed

+52
-39
lines changed

4 files changed

+52
-39
lines changed

lib/servers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private static function match($server, $user, $name) {
274274
return false;
275275
}
276276

277-
private static function appendPpasswordAndUsername(array $server) {
277+
private static function appendPasswordAndUsername(array $server) {
278278
$server['password'] = $server['pass'];
279279
$server['username'] = $server['user'];
280280
return $server;
@@ -283,15 +283,15 @@ private static function appendPpasswordAndUsername(array $server) {
283283
public static function getForMailbox($id) {
284284
$server = self::get($id, true);
285285
if ($server) {
286-
return self::appendPpasswordAndUsername($server);
286+
return self::appendPasswordAndUsername($server);
287287
}
288288
return false;
289289
}
290290

291291
public static function dumpForMailbox($id = false) {
292292
$list = self::dump($id, true);
293293
foreach ($list as $index => $server) {
294-
$server = self::appendPpasswordAndUsername($server);
294+
$server = self::appendPasswordAndUsername($server);
295295
$list[$index] = $server;
296296
}
297297
return $list;

modules/core/functions.php

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -639,32 +639,44 @@ function privacy_setting_callback($val, $key, $mod) {
639639
}
640640

641641
if (!hm_exists('get_scheduled_date')) {
642-
function get_scheduled_date($format, $only_label = false) {
643-
if ($format == 'later_in_day') {
644-
$date_string = 'today 18:00';
645-
$label = 'Later in the day';
646-
} elseif ($format == 'tomorrow') {
647-
$date_string = '+1 day 08:00';
648-
$label = 'Tomorrow';
649-
} elseif ($format == 'next_weekend') {
650-
$date_string = 'next Saturday 08:00';
651-
$label = 'Next weekend';
652-
} elseif ($format == 'next_week') {
653-
$date_string = 'next week 08:00';
654-
$label = 'Next week';
655-
} elseif ($format == 'next_month') {
656-
$date_string = 'next month 08:00';
657-
$label = 'Next month';
658-
} else {
659-
$date_string = $format;
660-
$label = 'Certain date';
661-
}
662-
$time = strtotime($date_string);
663-
if ($only_label) {
664-
return [$label, date('D, H:i', $time)];
665-
}
666-
return date('D, d M Y H:i', $time);
667-
}}
642+
function get_scheduled_date($format, $only_label = false) {
643+
switch ($format) {
644+
case 'later_in_day':
645+
$date_string = 'today 18:00';
646+
$label = 'Later in the day';
647+
break;
648+
case 'tomorrow':
649+
$date_string = '+1 day 08:00';
650+
$label = 'Tomorrow';
651+
break;
652+
case 'next_weekend':
653+
$date_string = 'next Saturday 08:00';
654+
$label = 'Next weekend';
655+
break;
656+
case 'next_week':
657+
$date_string = 'next week 08:00';
658+
$label = 'Next week';
659+
break;
660+
case 'next_month':
661+
$date_string = 'next month 08:00';
662+
$label = 'Next month';
663+
break;
664+
default:
665+
$date_string = $format;
666+
$label = 'Certain date';
667+
break;
668+
}
669+
670+
$time = strtotime($date_string);
671+
672+
if ($only_label) {
673+
return [$label, date('D, H:i', $time)];
674+
}
675+
676+
return date('D, d M Y H:i', $time);
677+
}
678+
}
679+
668680

669681
/**
670682
* @subpackage imap/functions
@@ -721,15 +733,16 @@ function parse_nexter_header($header, $name)
721733
{
722734
$header = str_replace("$name: ", '', $header);
723735
$result = [];
724-
foreach (explode(';', $header) as $kv)
736+
foreach (explode(';', $header) as $keyValue)
725737
{
726-
$kv = trim($kv);
727-
$spacePos = strpos($kv, ' ');
738+
$keyValue = trim($keyValue);
739+
$spacePos = strpos($keyValue, ' ');
728740
if ($spacePos > 0) {
729-
$result[rtrim(substr($kv, 0, $spacePos), ':')] = trim(substr($kv, $spacePos+1));
741+
$result[rtrim(substr($keyValue, 0, $spacePos), ':')] = trim(substr($keyValue, $spacePos+1));
730742
} else {
731-
$result[$kv] = true;
743+
$result[$keyValue] = true;
732744
}
733745
}
734746
return $result;
735-
}}
747+
}
748+
}

modules/core/message_list_functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ function subject_callback($vals, $style, $output_mod) {
336336
*/
337337
if (!hm_exists('date_callback')) {
338338
function date_callback($vals, $style, $output_mod) {
339-
$nexter_class = isset($vals[2]) && $vals[2]? ' nexter_date': '';
339+
$delayed_class = isset($vals[2]) && $vals[2]? ' delayed_date': '';
340340
if ($style == 'news') {
341-
return sprintf('<div class="msg_date%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></div>', $nexter_class, $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
341+
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]));
342342
}
343-
return sprintf('<td class="msg_date%s" title="%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></td>', $nexter_class, $output_mod->html_safe(date('r', $vals[1])), $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
343+
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]));
344344
}}
345345

346346
function dates_holders_callback($vals) {

modules/core/site.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ div.unseen,
12761276
.mobile .imap_sort {
12771277
width: 100%;
12781278
}
1279-
.nexter_date {
1279+
.delayed_date {
12801280
color: var(--bs-primary) !important;
12811281
}
12821282

0 commit comments

Comments
 (0)