*/
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 '
';
echo '
' . $this->getLang('menu') . '
';
echo '
';
echo '
';
switch ($current) {
case 'partner':
$this->showPartnerTab();
break;
case 'support':
$this->showSupportTab();
break;
}
echo '
';
}
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 '';
echo json_encode($data, JSON_PRETTY_PRINT);
echo '
';
}
/**
* 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 '';
foreach ($extensions as $ext) {
echo '- ';
echo '
';
echo '
';
echo '' . hsc($ext['name']) . '';
echo ' ' . hsc($ext['date']) . '';
echo '
';
echo '
' . hsc($ext['desc']) . '
';
// FIXME check if this version is newer than the installed one and highlight updates
if ($ext['token']) {
echo $this->getInstallForm($ext);
}
echo '
';
echo ' ';
}
echo '
';
}
/**
* 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 '';
}
/**
* 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();
}
}