-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
82 lines (68 loc) · 1.65 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
[$day_of_week, $month, $day_of_month] = explode(',', date('w,n,j'));
$days = json_decode(file_get_contents('days.json'), TRUE);
$day = $days[$day_of_week];
$name = $day['name'];
$holiday = FALSE;
foreach (json_decode(file_get_contents('holidays.json'), TRUE) as $date) {
if ($month == $date['month']) {
if (isset($date['day']) && $day_of_month == $date['day']) {
$holiday = TRUE;
break;
}
elseif (
isset($date['day-of-week']) &&
$day_of_week == $date['day-of-week']
) {
if (($expected_repeats = $date['repeats'] ?? 1) > 1) {
$found_repeats = 0;
$current_day_of_week = $day_of_week;
$current_day_of_month = $day_of_month;
while ($current_day_of_month--) {
if ($current_day_of_week == $day_of_week) {
$found_repeats++;
}
if ($current_day_of_week) {
$current_day_of_week--;
}
else {
$current_day_of_week = 6;
}
}
if ($found_repeats != $expected_repeats) {
continue;
}
}
$holiday = TRUE;
break;
}
}
}
if ($holiday) {
if (isset($day['delete'])) {
$name = mb_substr($name, $day['delete']);
}
/**
* Add dot(s) after a word to move the word to an icon as closely as possible.
*
* @see https://help.lametric.com/support/discussions/topics/6000060555
*/
if (isset($day['suffix'])) {
$name .= str_repeat('.', $day['suffix']);
}
/**
* The "UA" icon identifier.
*
* @see https://developer.lametric.com/icons
*
* @var int
*/
$icon = $day['icon'] ?? 46587;
}
$frame = ['text' => $name];
if (isset($icon)) {
$frame['icon'] = $icon;
}
$response = ['frames' => [$frame]];
header('Content-Type: text/json');
print json_encode($response);