register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'metaheader');
$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');
}
/**
* Add
EOT;
$form->addElement($canvasText);
// 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);
}
}
}
/**
* An event handler for newer versions of DokuWiki, starting from Igor.
*
* @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->setHiddenField("editfigure__new[$k]", $v);
}
}
}
/**
* Add a toolbar button to add a new figure
*
* @param Doku_Event $event
*/
public function toolbarDefine(Doku_Event $event, $param){
$event->data[] = array(
'type' => 'NewFigure',
'title' => 'New Figure',
'icon' => '../../plugins/' . $this->getPluginName() . '/images/figure.png',
'block' => true);
}
/**
* Handle the click on the new figure button in the toolbar
*
* @param Doku_Event $event
*/
function handle_newfigure($event) {
global $INPUT;
global $TEXT;
global $ACT;
if(!$INPUT->post->has('editfigure__new')) return;
/*
* $fields['pre'] has all data before the selection when the "Insert table" button was clicked
* $fields['text'] has all data inside the selection when the "Insert table" button was clicked
* $fields['suf'] has all data after the selection when the "Insert table" button was clicked
* $TEXT has the table created by the editor (from action_plugin_edittable_editor::handle_table_post())
*/
$fields = $INPUT->post->arr('editfigure__new');
// clean the fields (undos formText()) and update the post and request arrays
$fields['pre'] = cleanText($fields['pre']);
$fields['text'] = cleanText($fields['text']);
$fields['suf'] = cleanText($fields['suf']);
$INPUT->post->set('editfigure__new', $fields);
$ACT = act_clean($ACT);
switch($ACT){
case 'preview':
// preview view of a table edit
$INPUT->post->set('target', 'plugin_sketchcanvas');
break;
case 'edit':
// edit view of a table (first edit)
$INPUT->post->set('target', 'plugin_sketchcanvas');
$TEXT = "";
$lines = explode("\n", $fields['text']);
// Delete opening and closing tags from the input because they're not part of
// the figure source and the tags will be added on the save button anyway
if(preg_match('/^/', $lines[0]))
array_shift($lines);
if(preg_match('/^<\/skcanvas>/', end($lines)))
array_pop($lines);
foreach($lines as $line) {
$TEXT .= "$line\n";
}
break;
case 'draftdel':
// not sure if/how this would happen, we restore all data and hand over to section edit
$INPUT->post->set('target', 'section');
$TEXT = $fields['pre'].$fields['text'].$fields['suf'];
$INPUT->post->set('wikitext', $TEXT);
$event->data = 'edit';
break;
case 'save':
// return to edit page
$INPUT->post->set('target', 'section');
$TEXT = $fields['pre']."\n".$TEXT."".$fields['suf'];
$INPUT->post->set('wikitext', $TEXT);
$ACT = 'edit';
break;
}
}
}