diff --git a/action.php b/action.php index 2bd3bb7..72d2757 100644 --- a/action.php +++ b/action.php @@ -38,25 +38,25 @@ protected function makelist() { foreach ($conf as $button) { $ico = '../../plugins/custombuttons/'; if (!$button['icon']) { - $ico .= 'genpng.php?text=' . $button["label"]; + $ico .= 'genpng.php?text='. $button['label']; } else { - $ico .= 'ico/' . $button['icon']; + $ico .= 'ico/'. $button['icon']; } - if ($button["type"] == 1) { + if ($button['type'] == 1) { $buttonlist[] = array( 'type' => 'format', - 'title' => $button["label"], + 'title' => $button['label'], 'icon' => $ico, - 'open' => $button["pretag"], - 'close' => $button["posttag"] + 'open' => $button['pretag'], + 'close' => $button['posttag'] ); } else { $buttonlist[] = array( 'type' => 'insert', - 'title' => $button["label"], + 'title' => $button['label'], 'icon' => $ico, - 'insert' => $button["code"], + 'insert' => $button['code'], 'block' => true ); } diff --git a/admin.php b/admin.php index be469da..e7c2dc4 100644 --- a/admin.php +++ b/admin.php @@ -7,187 +7,181 @@ */ 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 - */ - 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"); - } - - 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(); - - echo ' -
'; - } + /** + * 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() { + + 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(); + } + } + + /** + * Render HTML output + */ + public function html() { + global $ID; + $conf = $this->loadCBData(); + + echo ' '; + } }