-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
config.php
119 lines (110 loc) · 4.46 KB
/
config.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace ReCalendar;
class Config {
public const DAY_NAMES_SHORT = 'day_names_short';
public const DAY_ITINERARY_ITEMS = 'day_itinerary_items';
public const DAY_ITINERARY_COMMON = 'day_itinerary_common';
public const DAY_ITINERARY_WEEK_RETRO = 'day_itinerary_week_retro';
public const DAY_ITINERARY_MONTH_OVERVIEW = 'day_itinerary_month_overview';
public const FORMAT = 'format';
public const HABITS = 'habits';
public const LOCALE = 'locale';
public const MONTHS = 'months';
public const WEEK_NAME = 'week_name';
public const WEEK_NUMBER = 'week_number';
public const WEEKLY_RETROSPECTIVE_BOOKMARK = 'weekly_retrospective_bookmark';
public const WEEKLY_RETROSPECTIVE_TITLE = 'weekly_retrospective_title';
public const WEEKLY_TODOS = 'weekly_todos';
public const SPECIAL_DATES = 'special_dates';
public const YEAR = 'year';
public function get( string $key ) {
return $this->get_configuration()[ $key ] ?? null;
}
protected function get_configuration() : array {
$configuration = [
// Used in the small calendar in the upper right corner of most pages
// Please try to use a 2 character abbreviations to save space on the page
self::DAY_NAMES_SHORT => [
'Mo',
'Tu',
'We',
'Th',
'Fr',
'Sa',
'Su',
],
// Items for each page type
// The format is: [ NUMBER OF LINES, NAME (optional) ]
// You might need to adjust the number of lines depending on your config (locale, font size, etc.)
self::DAY_ITINERARY_ITEMS => [
// Common itinerary used if nothing more specific was defined
self::DAY_ITINERARY_COMMON => [
[ 23, '', ],
],
// Itinerary for the weekly retrospective
self::DAY_ITINERARY_WEEK_RETRO => [
[ 24, '' ],
],
// Itinerary for the month's overview
self::DAY_ITINERARY_MONTH_OVERVIEW => [
[ 16, '' ],
],
],
// A list of habits that triggers generating a table on the month's overview
// to help tracking those habits
self::HABITS => [
],
// This is the exact size (in mm) of the ReMarkable 2 screen
// You might want to adjust it to your device's size
// See https://mpdf.github.io/reference/mpdf-functions/construct.html for possible values
self::FORMAT => [ 157, 209 ],
// Locale to generate the calendar in
// To check which locale your PHP version supports run:
// `locale -a` in your terminal (at least on Linux and MacOS)
// Note that you will still need to override some configuration variables, like `WEEK_NAME`, etc.
self::LOCALE => 'en_US.UTF-8',
// Title of the Week overview page
self::WEEK_NAME => 'Week',
// A short version of "Week Number" used in the header of the small calendar in upper right corner of the page
self::WEEK_NUMBER => 'W#',
// Used for the bookmark of the weekly retrospective pages
self::WEEKLY_RETROSPECTIVE_BOOKMARK => 'Retrospective',
// Used for the title of the weekly retrospective pages
self::WEEKLY_RETROSPECTIVE_TITLE => 'Weekly retrospective',
// A list of items you'd like to be listed in the notes of the weekly overview
self::WEEKLY_TODOS => [
],
// A list of special dates (anniversaries, birthdays, holidays) that will be highlighted throughout the calendar:
// in the small calendar, on weekly overviews and daily entries.
self::SPECIAL_DATES => [
// Example:
// '01-01' => "New Year!",
// '01-04' => "April Fools' Day",
],
// The year for which to generate this calendar.
// Defaults to the current year.
self::YEAR => (int) date( 'Y' ),
];
// Get the names of the months in the set locale.
// This might useful for non-English locales (like Polish), that apparently
// have their names decilned in the locale provided by the system, while
// you'd probably want a non-declined version.
// Example: 'stycznia' instead of 'Styczeń' for January in Polish.
$configuration[ self::MONTHS ] = $this->generate_month_names( $configuration[ self::LOCALE ] );
return $configuration;
}
private function generate_month_names( string $locale ) : array {
$old_locale = setlocale( LC_TIME, 0 );
setlocale( LC_TIME, $locale );
$start = new \DateTimeImmutable( 'first day of january' );
$interval = new \DateInterval( 'P1M' );
$end = new \DateTimeImmutable( 'last day of december' );
$period = new \DatePeriod( $start, $interval, $end );
$month_names = [];
foreach ( $period as $index => $month ) {
$month_names[ $index + 1 ] = strftime( '%B', $month->getTimestamp() );
}
setlocale( LC_TIME, $old_locale );
return $month_names;
}
}