From b8628df8538807bf1a459d26f3ec7a682bf84062 Mon Sep 17 00:00:00 2001 From: msakuta Date: Sun, 7 Jan 2024 17:02:06 +0900 Subject: [PATCH] Fix canvas editing GUI didn't work for Igor and later --- CanvasElement.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++ action.php | 30 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 CanvasElement.php diff --git a/CanvasElement.php b/CanvasElement.php new file mode 100644 index 0000000..1249b42 --- /dev/null +++ b/CanvasElement.php @@ -0,0 +1,73 @@ +text = $value; + return $this; + } + return $this->text; + } + + /** + * The HTML representation of this element + * + * @return string + */ + protected function mainElementHTML() + { + $escText = '"' . str_replace(array("\r", "\n"), array('\r', '\n'), addslashes($this->text)) . '"'; + + $attrs = buildAttributes($this->attrs()); + + $canvasText = << + + + +EOT; + return $canvasText; + } + +} diff --git a/action.php b/action.php index 3238822..462d8f1 100644 --- a/action.php +++ b/action.php @@ -9,6 +9,8 @@ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); +require_once("CanvasElement.php"); + /** * Add scripts via an event handler */ @@ -22,6 +24,8 @@ public function register(Doku_Event_Handler $controller) { $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'editButton'); $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, 'editForm'); + // After Igor + $controller->register_hook('EDIT_FORM_ADDTEXTAREA', 'BEFORE', $this, 'editFormNew'); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_newfigure'); $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'toolbarDefine'); @@ -121,6 +125,32 @@ public function editForm(Doku_Event $event, $param){ } } + /** + * A + * + * @param Doku_Event $event + */ + public function editFormNew(Doku_Event $event, $param){ + global $TEXT; + if($event->data['target'] !== 'plugin_sketchcanvas') + return; + $event->preventDefault(); + + $event->data['media_manager'] = false; + + $form =& $event->data['form']; + $canvasElem = new CanvasElement(); + $canvasElem->val($TEXT); + $form->addElement($canvasElem); + + // Pass wikitext through POSTs for previewing and saving + if(isset($_POST['editfigure__new'])) { + foreach($_POST['editfigure__new'] as $k => $v) { + $form->addHidden("editfigure__new[$k]", $v); + } + } + } + /** * Add a toolbar button to add a new figure *