*/ // 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('

Buttons List

'); ptln('
'); ptln(' '); ptln(' '); formSecurityToken(); ptln(' '); ptln(' '); if ($conf) { foreach ($conf as $key => $button) { if (!$button["type"]) { ptln(' '); ptln(' '); ptln(' '); ptln(' '); # FIXME Del image ptln(' '); } else { $icon = ''; if($button['icon']) { $icon = ' '; } ptln(' '); ptln(' '); ptln(' '); ptln(' '); # FIXME Del image ptln(' '); } } } ptln('
LabelCodeDelete?
' . hsc($button["label"]).''.hsc($button["code"]).'
' . $icon . hsc($button["label"]).''.hsc($button["pretag"]).hsc($button["code"]).hsc($button["posttag"]).'
'); ptln(''); ptln('
'); ptln('

'); ptln('

Add Button

'); ptln('
'); ptln(' '); ptln(' '); ptln(' '); formSecurityToken(); ptln(' '); ptln(' '); ptln(' '); ptln(' '); ptln(' '); ptln(' '); ptln('
Icon:'); ptln(''); ptln('
Label:
Pre tag: *
Post tag: *
Code:
'); ptln(' '); ptln('
'); ptln('

'); ptln('
* If you dont want to add a shortcut button with pre and post code leave those fields empty.
'); } }