-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
80 lines (65 loc) · 2.48 KB
/
init.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
<?php
class Version_Info extends Plugin {
/** @return array<null|float|string|bool> */
public function about() {
return [
null, // version
'Show the tt-rss version using Shift+V.', // description
'wn', // author
false, // is system
'https://github.com/supahgreg/ttrss-version-info', // more info URL
];
}
/** @return int */
public function api_version() {
return 2;
}
/**
* @param PluginHost $host
*
* @return void
**/
public function init($host): void {
$host->add_hook($host::HOOK_HOTKEY_MAP, $this);
$host->add_hook($host::HOOK_HOTKEY_INFO, $this);
}
/**
* @param array<string, string> $hotkeys
* @return array<string, string>
*/
public function hook_hotkey_map($hotkeys) {
$hotkeys['V'] = 'show_version';
return $hotkeys;
}
/**
* @param array<string, array<string, string>> $hotkeys
* @return array<string, array<string, string>>
*/
public function hook_hotkey_info($hotkeys) {
$hotkeys[__('Other')]['show_version'] = __('Show tt-rss version info');
// @phpstan-ignore-next-line '__()' returns strings
return $hotkeys;
}
public function show_version(): void {
/** @var array{'status': int, 'version': string, 'commit'?: string, 'timestamp'?: int|string} */
$ttrss_version = Config::get_version(false);
$is_git = array_key_exists('commit', $ttrss_version) && array_key_exists('timestamp', $ttrss_version);
if (!$is_git) {
print $ttrss_version['version'];
return;
}
$alpine_version = trim(file_get_contents('/etc/alpine-release') ?: 'unknown');
print '<strong>tt-rss:</strong> <a target="_blank" rel="noreferrer noopener" href="https://gitlab.tt-rss.org/tt-rss/tt-rss/-/commit/' . $ttrss_version['commit'] . '">';
print $ttrss_version['version'];
print ' (' . TimeHelper::make_local_datetime(gmdate("Y-m-d H:i:s", (int) $ttrss_version['timestamp']), true, null, true) . ')';
print '</a>';
print '<br>';
print '<strong>PHP:</strong> <a target="_blank" rel="noreferrer noopener" href="https://www.php.net/ChangeLog-' . \PHP_MAJOR_VERSION . '.php#' . \PHP_VERSION . '">' . \PHP_VERSION . '</a>';
print '<br>';
print '<strong>Alpine Linux:</strong> <a target="_blank" rel="noreferrer noopener" href="https://alpinelinux.org/posts/Alpine-'.$alpine_version.'-released.html'.'">' . $alpine_version . '</a>';
}
/** @return string */
public function get_js() {
return file_get_contents(__DIR__ . '/init.js') ?: '';
}
}