*/ class admin_plugin_custombuttons extends DokuWiki_Admin_Plugin { /** * Return true for access only by admins (config:superuser) or false if managers are allowed as well * * @return bool */ public function forAdminOnly() { return true; } /** * return prompt for admin menu */ public function getMenuText($language) { return $this->getLang('name'); } /** * Read config * * @return bool|mixed */ protected function loadCBData() { $file = @file_get_contents(DOKU_PLUGIN.'custombuttons/config.json'); if (!$file) return false; return json_decode($file, true); } /** * Store config * * @param $conf */ protected function saveCBData($conf) { $configfile = DOKU_PLUGIN.'custombuttons/config.json'; if (is_writable($configfile) || (!file_exists($configfile) && is_writable(DOKU_PLUGIN.'custombuttons'))) { file_put_contents($configfile, json_encode($conf)); } else { msg($this->getLang('txt_error'), -1); } } protected function reloadBar() { touch(DOKU_CONF.'local.php'); } /** * Execute the requested action */ public function handle() { global $INPUT; if ($INPUT->has('add')) { if (!checkSecurityToken()) return; $conf = $this->loadCBData(); if (!$conf) { $conf = array(); } $type = 0; if ($INPUT->str('pretag') != '' && $INPUT->str('posttag') != '') { $type = 1; } array_push($conf, array( 'label' => $INPUT->str('label'), 'code' => $INPUT->str('code'), 'type' => $type, 'pretag' => $INPUT->str('pretag'), 'posttag' => $INPUT->str('posttag'), 'icon' => $INPUT->str('icon'), )); $this->saveCBData($conf); $this->reloadBar(); } elseif ($INPUT->has('delete')) { if (!checkSecurityToken()) return; $conf = $this->loadCBData(); unset($conf[$INPUT->int('delete')]); $this->saveCBData($conf); $this->reloadBar(); } } /** * Render HTML output */ public function html() { global $ID; $conf = $this->loadCBData(); echo '
'; echo '

'.$this->getLang('name').'

'; // list of custom buttons echo '

'.$this->getLang('btnslist').'

'; echo '
' .'' .''; formSecurityToken(); echo ''; echo '' .'' .'' .'' .''; if ($conf) { foreach ($conf as $key => $button) { echo ''; if (!$button['type']) { echo '' .''; } else { $icon = ''; if ($button['icon']) { $icon = ' '; } echo '' .''; }; echo ''; echo ''; } } echo '
'.$this->getLang('btnslist_label').''.$this->getLang('btnslist_code').''.$this->getLang('btnslist_delete').'
'.hsc($button['label']).''.hsc($button['code']).''.$icon.hsc($button['label']).''.hsc($button['pretag']).hsc($button['code']).hsc($button['posttag']).'
'; echo ''; echo '
'; echo '

'; // add custom button form echo '

'.$this->getLang('addbtn').'

'; echo '
' .'' .'' .''; formSecurityToken(); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '' .'' .'' .'' .''; echo '' .'' .'' .'' .''; echo '' .'' .'' .'' .''; echo '' .'' .'' .'' .''; echo '
'.$this->getLang('addbtn_icon').'' .''; echo '
'.$this->getLang('addbtn_label').'
'.$this->getLang('addbtn_pretag').'*
'.$this->getLang('addbtn_posttag').'*
'.$this->getLang('addbtn_code').'
'; echo ''; echo '
'; echo '
'.$this->getLang('txt_comment').'
'; echo '
'; } }