Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions action/editor.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

/**
* Table editor
*
* @author Adrian Lang <lang@cosmocode.de>
* @author Andreas Gohr <gohr@cosmocode.de>
*/

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\Utf8\PhpString;
use dokuwiki\Form\Form;
use dokuwiki\Utf8;

Expand All @@ -14,12 +19,12 @@
*
* like displaying the editor and adding custom edit buttons
*/
class action_plugin_edittable_editor extends DokuWiki_Action_Plugin
class action_plugin_edittable_editor extends ActionPlugin
{
/**
* Register its handlers with the DokuWiki's event controller
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
// register custom edit buttons
$controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'secedit_button');
Expand All @@ -38,9 +43,9 @@ public function register(Doku_Event_Handler $controller)
*
* The target 'table' is provided by DokuWiki's XHTML core renderer in the table_close() method
*
* @param Doku_Event $event
* @param Event $event
*/
public function secedit_button(Doku_Event $event)
public function secedit_button(Event $event)
{
if ($event->data['target'] !== 'table') return;

Expand All @@ -50,16 +55,16 @@ public function secedit_button(Doku_Event $event)
/**
* Creates the actual Table Editor form
*
* @param Doku_Event $event
* @param Event $event
*/
public function editform(Doku_Event $event)
public function editform(Event $event)
{
global $TEXT;
global $RANGE;
global $INPUT;

if ($event->data['target'] !== 'table') return;
if (!$RANGE){
if (!$RANGE) {
// section editing failed, use default editor instead
$event->data['target'] = 'section';
return;
Expand All @@ -75,15 +80,15 @@ public function editform(Doku_Event $event)
// Loop through the instructions
foreach ($instructions as $instruction) {
// Execute the callback against the Renderer
call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]);
call_user_func_array([&$Renderer, $instruction[0]], $instruction[1]);
}

// output data and editor field

/** @var Doku_Form $form */
$form =& $event->data['form'];

if (is_a($form, Form::class)) { // $event->name is EDIT_FORM_ADDTEXTAREA
if ($form instanceof Form) { // $event->name is EDIT_FORM_ADDTEXTAREA
// data for handsontable
$form->setHiddenField('edittable_data', $Renderer->getDataJSON());
$form->setHiddenField('edittable_meta', $Renderer->getMetaJSON());
Expand All @@ -97,7 +102,6 @@ public function editform(Doku_Event $event)
// set target and range to keep track during previews
$form->setHiddenField('target', 'table');
$form->setHiddenField('range', $RANGE);

} else { // $event->name is HTML_EDIT_FORMSELECTION
// data for handsontable
$form->addHidden('edittable_data', $Renderer->getDataJSON());
Expand All @@ -122,7 +126,7 @@ public function editform(Doku_Event $event)
*
* @author Andreas Gohr <gohr@cosmocode,de>
*/
public function handle_table_post(Doku_Event $event)
public function handle_table_post(Event $event)
{
global $TEXT;
global $INPUT;
Expand All @@ -149,7 +153,7 @@ public function build_table($data, $meta)
$rows = count($data);
$cols = $rows ? count($data[0]) : 0;

$colmax = $cols ? array_fill(0, $cols, 0) : array();
$colmax = $cols ? array_fill(0, $cols, 0) : [];

// find maximum column widths
for ($row = 0; $row < $rows; $row++) {
Expand All @@ -173,7 +177,6 @@ public function build_table($data, $meta)
$last = '|'; // used to close the last cell
for ($row = 0; $row < $rows; $row++) {
for ($col = 0; $col < $cols; $col++) {

// hidden cells may carry no span info of their own
if (!isset($meta[$row][$col]['colspan'])) $meta[$row][$col]['colspan'] = 1;
if (!isset($meta[$row][$col]['rowspan'])) $meta[$row][$col]['rowspan'] = 1;
Expand Down Expand Up @@ -218,8 +221,8 @@ public function build_table($data, $meta)

// add the padding
$cdata = $data[$row][$col];
if (!(isset($meta[$row][$col]['hide']) && $meta[$row][$col]['hide']) || $cdata) {
$cdata = str_pad('', $lpad).$cdata.str_pad('', $rpad);
if (!isset($meta[$row][$col]['hide']) || !$meta[$row][$col]['hide'] || $cdata) {
$cdata = str_pad('', $lpad) . $cdata . str_pad('', $rpad);
}

// finally add the cell
Expand Down Expand Up @@ -248,19 +251,17 @@ public function strWidth($str)

if (isset($callable)) {
return $callable($str);
}
if (UTF8_MBSTRING) {
// count fullwidth characters as 2, halfwidth characters as 1
$callable = 'mb_strwidth';
} elseif (method_exists(PhpString::class, 'strlen')) {
// count any characters as 1
$callable = PhpString::strlen(...);
} else {
if (UTF8_MBSTRING) {
// count fullwidth characters as 2, halfwidth characters as 1
$callable = 'mb_strwidth';
} elseif (method_exists(Utf8\PhpString::class, 'strlen')) {
// count any characters as 1
$callable = [Utf8\PhpString::class, 'strlen'];
} else {
// fallback deprecated utf8_strlen since 2019-06-09
$callable = 'utf8_strlen';
}
return $this->strWidth($str);
// fallback deprecated utf8_strlen since 2019-06-09
$callable = 'utf8_strlen';
}
return $this->strWidth($str);
}

}
7 changes: 5 additions & 2 deletions action/jsinfo.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;

/**
* handles the data that has to be written into jsinfo
*
* like displaying the editor and adding custom edit buttons
*/
class action_plugin_edittable_jsinfo extends DokuWiki_Action_Plugin
class action_plugin_edittable_jsinfo extends ActionPlugin
{
/**
* Register its handlers with the DokuWiki's event controller
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
// register custom edit buttons
$controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'fill_jsinfo');
Expand Down
26 changes: 15 additions & 11 deletions action/newtable.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;

/**
* Table editor
*
* @author Adrian Lang <lang@cosmocode.de>
*/

/**
* Handles the inserting of a new table in a running edit session
*/
class action_plugin_edittable_newtable extends DokuWiki_Action_Plugin
class action_plugin_edittable_newtable extends ActionPlugin
{
/**
* Register its handlers with the DokuWiki's event controller
*/
function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'toolbar');

Expand All @@ -24,24 +28,24 @@ function register(Doku_Event_Handler $controller)
/**
* Add a button for inserting tables to the toolbar array
*
* @param Doku_Event $event
* @param Event $event
*/
public function toolbar(Doku_Event $event)
public function toolbar(Event $event)
{
$event->data[] = array(
$event->data[] = [
'title' => $this->getLang('add_table'),
'type' => 'NewTable',
'icon' => '../../plugins/edittable/images/add_table.png',
'block' => true
);
];
}

/**
* Handle the click on the new table button in the toolbar
*
* @param Doku_Event $event
* @param Event $event
*/
public function handle_newtable(Doku_Event $event)
public function handle_newtable(Event $event)
{
global $INPUT;
global $TEXT;
Expand Down Expand Up @@ -80,13 +84,13 @@ public function handle_newtable(Doku_Event $event)
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'];
$TEXT = $fields['pre'] . $fields['text'] . $fields['suf'];
$event->data = 'edit';
break;
case 'save':
// return to edit page
$INPUT->post->set('target', 'section');
$TEXT = $fields['pre'].$TEXT.$fields['suf'];
$TEXT = $fields['pre'] . $TEXT . $fields['suf'];
$event->data = 'edit';
break;
}
Expand Down
11 changes: 7 additions & 4 deletions action/preprocess.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

/**
* Table editor
*
* @author Andreas Gohr <gohr@cosmocode.de>
*/

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;

/**
Expand All @@ -14,12 +17,12 @@
* That's currently not possible to guarantee, so we catch the event only once and emit two of our own
* in the right order. Once DokuWiki supports a sort we can skip this.
*/
class action_plugin_edittable_preprocess extends DokuWiki_Action_Plugin
class action_plugin_edittable_preprocess extends ActionPlugin
{
/**
* Register its handlers with the DokuWiki's event controller
*/
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
// register preprocessing for accepting editor data
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_preprocess');
Expand All @@ -28,9 +31,9 @@ public function register(Doku_Event_Handler $controller)
/**
* See class description for WTF we're doing here
*
* @param Doku_Event $event
* @param Event $event
*/
public function handle_preprocess(Doku_Event $event)
public function handle_preprocess(Event $event)
{
Event::createAndTrigger('PLUGIN_EDITTABLE_PREPROCESS_EDITOR', $event->data);
Event::createAndTrigger('PLUGIN_EDITTABLE_PREPROCESS_NEWTABLE', $event->data);
Expand Down
14 changes: 9 additions & 5 deletions action/sectionjump.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;

/**
* Table editor
*
* @author Adrian Lang <lang@cosmocode.de>
*/

/**
* redirect to the section containg the table
*/
class action_plugin_edittable_sectionjump extends DokuWiki_Action_Plugin
class action_plugin_edittable_sectionjump extends ActionPlugin
{
/**
* Register its handlers with the DokuWiki's event controller
*/
function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'jump_to_section');
}

/**
* Jump after save to the section containing this table
*
* @param Doku_Event $event
* @param Event $event
*/
function jump_to_section($event)
public function jump_to_section($event)
{
global $INPUT;
if (!$INPUT->has('edittable_data')) return;
Expand Down
Loading