-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
182 lines (158 loc) · 5.25 KB
/
admin.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
use dokuwiki\Extension\AdminPlugin;
use dokuwiki\Form\Form;
/**
* DokuWiki Plugin cosmocode (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
class admin_plugin_cosmocode extends AdminPlugin
{
/** @var helper_plugin_cosmocode_support */
protected $hlp_support;
/** @var helper_plugin_cosmocode_partner */
protected $hlp_partner;
public function __construct()
{
$this->hlp_support = $this->loadHelper('cosmocode_support');
$this->hlp_partner = $this->loadHelper('cosmocode_partner');
}
/** @inheritDoc */
public function handle()
{
// FIXME data processing
}
/** @inheritDoc */
public function html()
{
global $ID;
global $INPUT;
$tabs = [
'support' => wl($ID, ['do' => 'admin', 'page' => 'cosmocode', 'tab' => 'support']),
'partner' => wl($ID, ['do' => 'admin', 'page' => 'cosmocode', 'tab' => 'partner']),
];
$current = $INPUT->str('tab', 'support');
echo '<div class="plugin_cosmocode">';
echo '<h1>' . $this->getLang('menu') . '</h1>';
echo '<ul class="tabs">';
foreach ($tabs as $tab => $url) {
$class = ($current === $tab) ? 'active' : '';
echo "<li class='$class'>";
echo '<a href="' . $url . '">' . $this->getLang('tab_' . $tab) . '</a>';
echo '</li>';
}
echo '</ul>';
echo '<br>';
switch ($current) {
case 'partner':
$this->showPartnerTab();
break;
case 'support':
$this->showSupportTab();
break;
}
echo '</div>';
}
protected function showPartnerTab()
{
$this->showTokenInfo();
$this->showFeed();
}
protected function showSupportTab()
{
echo $this->locale_xhtml('support');
global $conf;
$data = [
'dt' => dformat(null, '%Y-%m-%d'),
'partner' => array_values($this->hlp_partner->getTokens()),
'dokuwiki' => getVersionData(),
'conf' => array_merge(
array_intersect_key($conf, array_flip(
['title', 'tagline', 'baseurl', 'basedir', 'savedir', 'useacl', 'authtype', 'template']
)),
[
'wiki-id' => md5(auth_cookiesalt()),
'inc' => DOKU_INC,
],
),
'environment' => $this->hlp_support->getRuntimeVersions(),
'plugins' => $this->hlp_support->getPlugins(),
'extensions' => get_loaded_extensions(),
];
echo '<div class="envdata">';
echo json_encode($data, JSON_PRETTY_PRINT);
echo '</div>';
}
/**
* Show the list of available extensions
*/
protected function showFeed()
{
try {
$extensions = $this->hlp_partner->getExtensions();
} catch (\Exception $e) {
msg(nl2br(hsc($e->getMessage())), -1);
return;
}
echo '<ul class="extensions">';
foreach ($extensions as $ext) {
echo '<li>';
echo '<div class="li">';
echo '<h2>';
echo '<a href="' . hsc($ext['url']) . '" class="urlextern" target="_blank">' . hsc($ext['name']) . '</a>';
echo ' <span>' . hsc($ext['date']) . '</span>';
echo '</h2>';
echo '<p>' . hsc($ext['desc']) . '</p>';
// FIXME check if this version is newer than the installed one and highlight updates
if ($ext['token']) {
echo $this->getInstallForm($ext);
}
echo '</div>';
echo '</li>';
}
echo '</ul>';
}
/**
* Tell the user about their current partner status
* @return void
*/
protected function showTokenInfo()
{
$tokens = $this->hlp_partner->getTokens();
if (!$tokens) {
echo $this->locale_xhtml('partner-no');
return;
}
echo $this->locale_xhtml('partner-yes');
echo '<ul class="tokens">';
foreach ($tokens as $token => $data) {
echo '<li class="token"><div class="li">';
if ($data['scopes'][0] === '') {
echo 'Partner Token';
} else {
echo hsc($data['scopes'][0]) . ' Token';
}
echo ' ' . sprintf($this->getLang('valid_until'), dformat($data['exp']));
echo '</div></li>';
}
echo '</ul>';
}
/**
* Create a form that submits the special download URL to the extension manager
*
* @param array $ext
* @return string
*/
protected function getInstallForm($ext)
{
global $ID;
$dl = $this->hlp_partner->getDownloadUrl($ext['base'], $ext['token']);
$action = wl($ID, ['do' => 'admin', 'page' => 'extension', 'tab' => 'install'], false, '&');
$form = new Form(['action' => $action]);
$form->setHiddenField('installurl', $dl);
$form->setHiddenField('overwrite', 1);
$form->addButton('submit', $this->getLang('btn_install'))->attr('type', 'submit');
return $form->toHTML();
}
}