-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.php
More file actions
62 lines (50 loc) · 2.21 KB
/
extension.php
File metadata and controls
62 lines (50 loc) · 2.21 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
<?php
class DateFormatExtension extends Minz_Extension {
private const DEFAULT_RELATIVE_DATE = false;
private const DEFAULT_ADJUSTED_DATE = false;
private const DEFAULT_HOUR12_DATE = false;
private const DEFAULT_CUSTOM_FORMAT = null;
public function init(): void {
$this->registerTranslates();
Minz_View::appendScript($this->getFileUrl('moment-with-locales.js', 'js'));
Minz_View::appendScript($this->getFileUrl('date-format.js', 'js'));
if (version_compare(FRESHRSS_VERSION, 1.28) >= 0) {
$this->registerHook(Minz_HookType::JsVars, [$this, 'addVariables']);
} else {
$this->registerHook('js_vars', [$this, 'addVariables']);
}
}
public function addVariables($vars): array {
$vars[$this->getName()]['configuration'] = [
'relativeDates' => $this->getRelativeDates(),
'adjustedDates' => $this->getAdjustedDates(),
'hour12Dates' => $this->getHour12Dates(),
'customFormat' => $this->getCustomFormat(),
];
return $vars;
}
public function handleConfigureAction(): void {
$this->registerTranslates();
if (Minz_Request::isPost()) {
$configuration = [
'relativeDates' => Minz_Request::paramBoolean('relative-dates'),
'adjustedDates' => Minz_Request::paramBoolean('adjusted-dates'),
'hour12Dates' => Minz_Request::paramBoolean('hour12-dates'),
'customFormat' => Minz_Request::paramStringNull('custom-format'),
];
$this->setUserConfiguration($configuration);
}
}
public function getRelativeDates(): bool {
return $this->getUserConfigurationValue('relativeDates', static::DEFAULT_RELATIVE_DATE);
}
public function getAdjustedDates(): bool {
return $this->getUserConfigurationValue('adjustedDates', static::DEFAULT_ADJUSTED_DATE);
}
public function getHour12Dates(): bool {
return $this->getUserConfigurationValue('hour12Dates', static::DEFAULT_HOUR12_DATE);
}
public function getCustomFormat(): ?string {
return $this->getUserConfigurationValue('customFormat', static::DEFAULT_CUSTOM_FORMAT);
}
}