*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); /** * Class admin_plugin_custombuttons */ 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; } /** * Read config * * @return bool|mixed */ protected function loadCBData() { $json = new JSON(JSON_LOOSE_TYPE); $file = @file_get_contents(DOKU_PLUGIN."custombuttons/config.json"); if(!$file) return false; return $json->decode($file); } /** * Store config * * @param $conf */ protected function saveCBData($conf) { $json = new JSON(); $json = $json->encode($conf); $configfile = DOKU_PLUGIN."custombuttons/config.json"; if(is_writable($configfile) || (!file_exists($configfile) && is_writable(DOKU_PLUGIN."custombuttons"))) { file_put_contents($configfile, $json); } else { msg('No write access to config file', -1); } } protected function reloadBar() { touch(DOKU_CONF."local.php"); } public function handle() { if (isset($_REQUEST['add'])) { if (!checkSecurityToken()) return; $conf = $this->loadCBData(); if(!$conf) { $conf = array(); } $type = 0; if ($_REQUEST["pretag"] != "" && $_REQUEST["posttag"] != "") { $type = 1; } array_push($conf, array( "label" => $_REQUEST["label"], "code" => $_REQUEST["code"], "type" => $type, "pretag" => $_REQUEST["pretag"], "posttag" => $_REQUEST["posttag"], "icon" => $_REQUEST["icon"], )); $this->saveCBData($conf); $this->reloadBar(); } elseif (isset($_REQUEST['delete'])) { if (!checkSecurityToken()) return; $conf = $this->loadCBData(); unset($conf[$_REQUEST["delete"]]); $this->saveCBData($conf); $this->reloadBar(); } } public function html() { global $ID; $conf = $this->loadCBData(); ptln('