-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
128 lines (102 loc) · 3.34 KB
/
Copy pathconfig.php
File metadata and controls
128 lines (102 loc) · 3.34 KB
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
120
121
122
123
124
125
126
127
128
<?php
// SQL-based configuration.
namespace config;
$_DEFAULTS = [];
$_CONFIG = \store\config();
foreach($_CONFIG as $key => $value) {
define(normalize_key($key), normalize_value($value));
}
required('host');
fallback('force-https', false);
fallback('prefered-proto', FORCE_HTTPS ? "https" : "http");
fallback('secure', PREFERED_PROTO == "https");
fallback('canonical', PREFERED_PROTO . "://" . HOST);
fallback('timezone', getenv("TIMEZONE") ?: "Europe/Amsterdam");
fallback('time-format', "24-hour");
resolute('time-lang', TIME_FORMAT == '24-hour' ? 'nl' : 'en');
fallback('currency', "eur");
fallback('country', "NL");
fallback('phone-region', "NL");
fallback('map-provider', "google_maps");
fallback('developer-mode', $_ENV == 'dev');
fallback('ui.panel-position', "right");
fallback('ui.sidebar-position', "left");
fallback('ui.habits-position', "bottom");
fallback('ui.border-radius', "subtle");
fallback('ui.default-application', "todo");
fallback('ui.insert-application', UI_DEFAULT_APPLICATION);
optional('developer.custom-css');
fallback('developer.git-enabled', false);
optional('developer.git-repository');
fallback('calendar.default-calendar', @\store\get_first_calendar()['id']);
fallback('calendar.redacted-titles', false);
fallback('notes.layout', "masonry");
fallback('mail.default-account', @\store\get_first_imap_credentials()['id']);
optional('mail.notes-account');
fallback('todo.default-query', "is:open not:expired");
fallback('todo.recurrence-horizon', 3);
fallback('todo.layout', "masonry");
fallback('todo.display', "tag");
fallback('contacts.default-query', "is:person");
fallback('contacts.display-format', "first_last");
fallback('contacts.sort-order', "first");
fallback('contacts.prefer-nickname', false);
fallback('contacts.picture_max_edge', 1024);
fallback('contacts.picture_max_pixels', 40 * 1000 * 1000);
fallback('contacts.picture_mimes', ['image/jpeg', 'image/png', 'image/webp', 'image/gif']);
resolute('contacts.upload_limit', ini_get('upload_max_filesize'));
function required($key) {
if(!defined(normalize_key($key))) {
fail("Missing required key '$key' in config.");
}
}
function fallback($key, $value) {
global $_DEFAULTS;
$key = normalize_key($key);
if(!defined($key)) {
$_DEFAULTS[$key] = $value;
define($key, $value);
}
}
function resolute($key, $value) {
$key = normalize_key($key);
if(defined($key)) {
fail("Resolute key '$key' cannot be overridden.");
} else {
define($key, $value);
}
}
function optional($key) {
// Do nothing, this is just here to document
// what configuration is available.
}
function is_set($key) {
global $_CONFIG;
$key = normalize_key($key);
return isset($_CONFIG[$key]);
}
function is_fallback($key) {
global $_DEFAULTS;
$key = normalize_key($key);
return isset($_DEFAULTS[$key]);
}
function normalize_key($key) {
$key = str_replace("-", "_", $key);
$key = str_replace(".", "_", $key);
return strtoupper($key);
}
function normalize_value($value) {
return match($value) {
"true", "on", "yes" => true,
"false", "off", "no" => false,
default => $value
};
}
function canonical_value($key) {
$stored = @\store\config()[$key];
return $stored === null ? null : normalize_value($stored);
}
function fresh_value($key) {
$stored = @\store\config()[$key];
return $stored === null ? constant(normalize_key($key)) : normalize_value($stored);
}