*/ 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 '
'; } }