-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
92 lines (80 loc) · 2.82 KB
/
action.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
<?php
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler;
/**
* DokuWiki Plugin golocal (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
class action_plugin_golocal extends ActionPlugin
{
/** @inheritDoc */
public function register(EventHandler $controller)
{
$controller->register_hook('INIT_LANG_LOAD', 'AFTER', $this, 'handleInitLangLoad');
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActionActPreprocess');
$controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'handleTplActUnknown');
}
/**
* Event handler for INIT_LANG_LOAD
*
* @see https://www.dokuwiki.org/devel:events:init_lang_load
* @param Event $event Event object
* @param mixed $param optional parameter passed when event was registered
* @return void
*/
public function handleInitLangLoad(Event $event, $param)
{
global $lang;
$lang['js']['nosmblinks'] = '';
}
/**
* Event handler for ACTION_ACT_PREPROCESS
*
* @see https://www.dokuwiki.org/devel:events:action_act_preprocess
* @param Event $event Event object
* @param mixed $param optional parameter passed when event was registered
* @return void
*/
public function handleActionActPreprocess(Event $event, $param)
{
if ($event->data !== 'golocal') return;
$event->preventDefault();
$event->stopPropagation();
}
public function handleTplActUnknown(Event $event, $param)
{
if ($event->data !== 'golocal') return;
$event->preventDefault();
$event->stopPropagation();
$output = $this->locale_xhtml('download');
$output = str_replace('DOWNLOADSHERE', $this->getDownloadLinks(), $output);
echo $output;
}
/**
* Build the list of downloads
*
* @return string
* @todo this could be a syntax component
* @todo this could refer to the release matching the installed version
*/
protected function getDownloadLinks()
{
$oslist = ['windows', 'linux', 'macos'];
$html = '<ul class="golocal-download">';
foreach ($oslist as $os) {
$file = 'golocal-' . $os;
$file .= $os === 'windows' ? '.exe' : '';
$url = 'https://github.com/cosmocode/dokuwiki-plugin-golocal/releases/latest/download/' . $file;
$classes = implode(' ', ['li', 'os-' . $os]);
$html .= '<li><div class="' . $classes . '">';
$html .= inlineSVG(__DIR__ . '/icons/' . $os . '.svg');
$html .= '<a href="' . $url . '">' . $file . '</a>';
$html .= '</div></li>';
}
$html .= '</ul>';
return $html;
}
}