mirror of
https://github.com/cosmocode/dokuwiki-plugin-prosemirror.git
synced 2025-08-15 23:39:12 +00:00
Code style fixes
This commit is contained in:
104
action/ajax.php
104
action/ajax.php
@ -7,7 +7,6 @@
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
use dokuwiki\Extension\ActionPlugin;
|
||||
use dokuwiki\Extension\EventHandler;
|
||||
use dokuwiki\Extension\Event;
|
||||
@ -17,10 +16,6 @@ use dokuwiki\plugin\prosemirror\parser\LocalLinkNode;
|
||||
use dokuwiki\plugin\prosemirror\parser\InternalLinkNode;
|
||||
use dokuwiki\plugin\prosemirror\parser\LinkNode;
|
||||
|
||||
if (!defined('DOKU_INC')) {
|
||||
die();
|
||||
}
|
||||
|
||||
class action_plugin_prosemirror_ajax extends ActionPlugin
|
||||
{
|
||||
/**
|
||||
@ -42,12 +37,10 @@ class action_plugin_prosemirror_ajax extends ActionPlugin
|
||||
* Event: AJAX_CALL_UNKNOWN
|
||||
*
|
||||
* @param Event $event event object by reference
|
||||
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
|
||||
* handler was registered]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handleAjax(Event $event, $param)
|
||||
public function handleAjax(Event $event)
|
||||
{
|
||||
if ($event->data !== 'plugin_prosemirror') {
|
||||
return;
|
||||
@ -61,61 +54,52 @@ class action_plugin_prosemirror_ajax extends ActionPlugin
|
||||
foreach ($INPUT->arr('actions') as $action) {
|
||||
switch ($action) {
|
||||
case 'resolveInternalLink':
|
||||
{
|
||||
$inner = $INPUT->str('inner');
|
||||
$responseData[$action] = $this->resolveInternalLink($inner, $ID);
|
||||
break;
|
||||
}
|
||||
$inner = $INPUT->str('inner');
|
||||
$responseData[$action] = $this->resolveInternalLink($inner, $ID);
|
||||
break;
|
||||
case 'resolveInterWikiLink':
|
||||
{
|
||||
$inner = $INPUT->str('inner');
|
||||
[$shortcut, $reference] = explode('>', $inner);
|
||||
$responseData[$action] = $this->resolveInterWikiLink($shortcut, $reference);
|
||||
break;
|
||||
}
|
||||
$inner = $INPUT->str('inner');
|
||||
[$shortcut, $reference] = explode('>', $inner);
|
||||
$responseData[$action] = $this->resolveInterWikiLink($shortcut, $reference);
|
||||
break;
|
||||
case 'resolveMedia':
|
||||
{
|
||||
$attrs = $INPUT->arr('attrs');
|
||||
$responseData[$action] = [
|
||||
'data-resolvedHtml' => ImageNode::resolveMedia(
|
||||
$attrs['id'],
|
||||
$attrs['title'],
|
||||
$attrs['align'],
|
||||
$attrs['width'],
|
||||
$attrs['height'],
|
||||
$attrs['cache'],
|
||||
$attrs['linking']
|
||||
)
|
||||
];
|
||||
break;
|
||||
}
|
||||
$attrs = $INPUT->arr('attrs');
|
||||
$responseData[$action] = [
|
||||
'data-resolvedHtml' => ImageNode::resolveMedia(
|
||||
$attrs['id'],
|
||||
$attrs['title'],
|
||||
$attrs['align'],
|
||||
$attrs['width'],
|
||||
$attrs['height'],
|
||||
$attrs['cache'],
|
||||
$attrs['linking']
|
||||
)
|
||||
];
|
||||
break;
|
||||
case 'resolveImageTitle':
|
||||
{
|
||||
$image = $INPUT->arr('image');
|
||||
$responseData[$action] = [];
|
||||
$responseData[$action]['data-resolvedImage'] = LinkNode::resolveImageTitle(
|
||||
$ID,
|
||||
$image['id'],
|
||||
$image['title'],
|
||||
$image['align'],
|
||||
$image['width'],
|
||||
$image['height'],
|
||||
$image['cache']
|
||||
);
|
||||
break;
|
||||
}
|
||||
$image = $INPUT->arr('image');
|
||||
$responseData[$action] = [];
|
||||
$responseData[$action]['data-resolvedImage'] = LinkNode::resolveImageTitle(
|
||||
$ID,
|
||||
$image['id'],
|
||||
$image['title'],
|
||||
$image['align'],
|
||||
$image['width'],
|
||||
$image['height'],
|
||||
$image['cache']
|
||||
);
|
||||
break;
|
||||
case 'resolveRSS':
|
||||
{
|
||||
$attrs = json_decode($INPUT->str('attrs'), true);
|
||||
$responseData[$action] = RSSNode::renderAttrsToHTML($attrs);
|
||||
break;
|
||||
}
|
||||
$attrs = json_decode($INPUT->str('attrs'), true);
|
||||
$responseData[$action] = RSSNode::renderAttrsToHTML($attrs);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
dbglog('Unknown action: ' . $action, __FILE__ . ': ' . __LINE__);
|
||||
http_status(400, 'unknown action');
|
||||
return;
|
||||
}
|
||||
dokuwiki\Logger::getInstance(dokuwiki\Logger::LOG_DEBUG)->log(
|
||||
__FILE__ . ': ' . __LINE__,
|
||||
'Unknown action: ' . $action
|
||||
);
|
||||
http_status(400, 'unknown action');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,12 +132,10 @@ class action_plugin_prosemirror_ajax extends ActionPlugin
|
||||
* Event: AJAX_CALL_UNKNOWN
|
||||
*
|
||||
* @param Event $event event object by reference
|
||||
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
|
||||
* handler was registered]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function switchEditors(Event $event, $param)
|
||||
public function switchEditors(Event $event)
|
||||
{
|
||||
if ($event->data !== 'plugin_prosemirror_switch_editors') {
|
||||
return;
|
||||
|
@ -7,17 +7,12 @@
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
use dokuwiki\Extension\ActionPlugin;
|
||||
use dokuwiki\Extension\EventHandler;
|
||||
use dokuwiki\Extension\Event;
|
||||
use dokuwiki\Form\Form;
|
||||
use dokuwiki\Form\ButtonElement;
|
||||
|
||||
if (!defined('DOKU_INC')) {
|
||||
die();
|
||||
}
|
||||
|
||||
class action_plugin_prosemirror_editor extends ActionPlugin
|
||||
{
|
||||
/**
|
||||
@ -208,7 +203,9 @@ class action_plugin_prosemirror_editor extends ActionPlugin
|
||||
$linkForm->addRadioButton('linktype', $this->getLang('type:wiki page'))->val('internallink');
|
||||
$linkForm->addRadioButton('linktype', $this->getLang('type:interwiki'))->val('interwikilink');
|
||||
$linkForm->addRadioButton('linktype', $this->getLang('type:email'))->val('emaillink');
|
||||
$linkForm->addRadioButton('linktype', $this->getLang('type:external'))->val('externallink')->attr('checked', 'checked');
|
||||
$linkForm->addRadioButton('linktype', $this->getLang('type:external'))
|
||||
->val('externallink')
|
||||
->attr('checked', 'checked');
|
||||
$linkForm->addRadioButton('linktype', $this->getLang('type:other'))->val('other');
|
||||
$linkForm->addTagClose('fieldset');
|
||||
$linkForm->addTagClose('div');
|
||||
@ -218,7 +215,9 @@ class action_plugin_prosemirror_editor extends ActionPlugin
|
||||
$linkForm->addTagOpen('legend');
|
||||
$linkForm->addHTML('Link Name Type');
|
||||
$linkForm->addTagClose('legend');
|
||||
$linkForm->addRadioButton('nametype', $this->getLang('type:automatic title'))->val('automatic')->attr('checked', 'checked');
|
||||
$linkForm->addRadioButton('nametype', $this->getLang('type:automatic title'))
|
||||
->val('automatic')
|
||||
->attr('checked', 'checked');
|
||||
$linkForm->addRadioButton('nametype', $this->getLang('type:custom title'))->val('custom');
|
||||
$linkForm->addRadioButton('nametype', $this->getLang('type:image'))->val('image');
|
||||
$linkForm->addTextInput('linkname', 'Link name')->attr('placeholder', $this->getLang('placeholder:link name'));
|
||||
@ -240,9 +239,12 @@ class action_plugin_prosemirror_editor extends ActionPlugin
|
||||
'style' => 'display: none;',
|
||||
]);
|
||||
$mediaForm->addFieldsetOpen($this->getLang('legend:media'))->addClass('js-media-fieldset');
|
||||
$mediaForm->addButtonHTML('mediamanager', inlineSVG(DOKU_PLUGIN . 'prosemirror/images/file-image-outline.svg'))->attrs([
|
||||
'type' => 'button',
|
||||
'class' => 'js-open-mediamanager mediaform_mediamanager'
|
||||
$mediaForm->addButtonHTML(
|
||||
'mediamanager',
|
||||
inlineSVG(DOKU_PLUGIN . 'prosemirror/images/file-image-outline.svg')
|
||||
)->attrs([
|
||||
'type' => 'button',
|
||||
'class' => 'js-open-mediamanager mediaform_mediamanager'
|
||||
]);
|
||||
$mediaForm->addTextInput('mediatarget', $this->getLang('media target'))->attrs(
|
||||
[
|
||||
@ -272,7 +274,9 @@ class action_plugin_prosemirror_editor extends ActionPlugin
|
||||
$mediaForm->addTagOpen('legend');
|
||||
$mediaForm->addHTML($this->getLang('legend:alignment'));
|
||||
$mediaForm->addTagClose('legend');
|
||||
$mediaForm->addRadioButton('alignment', $this->getLang('label:default alignment'))->val('')->attr('checked', 'checked');
|
||||
$mediaForm->addRadioButton('alignment', $this->getLang('label:default alignment'))
|
||||
->val('')
|
||||
->attr('checked', 'checked');
|
||||
$mediaForm->addRadioButton('alignment', $this->getLang('label:float left'))->val('left');
|
||||
$mediaForm->addRadioButton('alignment', $this->getLang('label:center alignment'))->val('center');
|
||||
$mediaForm->addRadioButton('alignment', $this->getLang('label:float right'))->val('right');
|
||||
@ -284,7 +288,9 @@ class action_plugin_prosemirror_editor extends ActionPlugin
|
||||
$mediaForm->addTagOpen('legend');
|
||||
$mediaForm->addHTML($this->getLang('legend:linking'));
|
||||
$mediaForm->addTagClose('legend');
|
||||
$mediaForm->addRadioButton('linking', $this->getLang('label:default linking'))->val('details')->attr('checked', 'checked');
|
||||
$mediaForm->addRadioButton('linking', $this->getLang('label:default linking'))
|
||||
->val('details')
|
||||
->attr('checked', 'checked');
|
||||
$mediaForm->addRadioButton('linking', $this->getLang('label:direct linking'))->val('direct');
|
||||
$mediaForm->addRadioButton('linking', $this->getLang('label:nolink'))->val('nolink');
|
||||
$mediaForm->addRadioButton('linking', $this->getLang('label:linkonly'))->val('linkonly');
|
||||
@ -296,7 +302,9 @@ class action_plugin_prosemirror_editor extends ActionPlugin
|
||||
$mediaForm->addTagOpen('legend');
|
||||
$mediaForm->addHTML($this->getLang('legend:caching'));
|
||||
$mediaForm->addTagClose('legend');
|
||||
$mediaForm->addRadioButton('caching', $this->getLang('label:default caching'))->val('')->attr('checked', 'checked');
|
||||
$mediaForm->addRadioButton('caching', $this->getLang('label:default caching'))
|
||||
->val('')
|
||||
->attr('checked', 'checked');
|
||||
$mediaForm->addRadioButton('caching', $this->getLang('label:recache'))->val('recache');
|
||||
$mediaForm->addRadioButton('caching', $this->getLang('label:nocache'))->val('nocache');
|
||||
$mediaForm->addTagClose('fieldset');
|
||||
|
@ -7,16 +7,11 @@
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
use dokuwiki\Extension\ActionPlugin;
|
||||
use dokuwiki\Extension\EventHandler;
|
||||
use dokuwiki\Extension\Event;
|
||||
use dokuwiki\plugin\prosemirror\parser\SyntaxTreeBuilder;
|
||||
|
||||
if (!defined('DOKU_INC')) {
|
||||
die();
|
||||
}
|
||||
|
||||
class action_plugin_prosemirror_parser extends ActionPlugin
|
||||
{
|
||||
/**
|
||||
@ -28,8 +23,8 @@ class action_plugin_prosemirror_parser extends ActionPlugin
|
||||
*/
|
||||
public function register(EventHandler $controller)
|
||||
{
|
||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_preprocess');
|
||||
$controller->register_hook('DRAFT_SAVE', 'BEFORE', $this, 'handle_draft');
|
||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handlePreprocess');
|
||||
$controller->register_hook('DRAFT_SAVE', 'BEFORE', $this, 'handleDraft');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +33,7 @@ class action_plugin_prosemirror_parser extends ActionPlugin
|
||||
* @param Event $event
|
||||
* @param $param
|
||||
*/
|
||||
public function handle_draft(Event $event, $param)
|
||||
public function handleDraft(Event $event, $param)
|
||||
{
|
||||
global $INPUT;
|
||||
$unparsedJSON = $INPUT->post->str('prosemirror_json');
|
||||
@ -80,7 +75,7 @@ class action_plugin_prosemirror_parser extends ActionPlugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_preprocess(Event $event, $param)
|
||||
public function handlePreprocess(Event $event, $param)
|
||||
{
|
||||
global $TEXT, $INPUT;
|
||||
if (
|
||||
|
@ -76,7 +76,11 @@ abstract class Node implements NodeInterface
|
||||
}
|
||||
return $eventData['newNode'];
|
||||
} catch (\Error $e) {
|
||||
$exception = new ProsemirrorException('FIXME: better message for general error! Invalid node type received: ' . $node['type'], 0, $e);
|
||||
$exception = new ProsemirrorException(
|
||||
'FIXME: better message for general error! Invalid node type received: ' . $node['type'],
|
||||
0,
|
||||
$e
|
||||
);
|
||||
$exception->addExtraData('nodeData', $node);
|
||||
$exception->addExtraData('parentNodeType', get_class($parent));
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
||||
|
||||
/**
|
||||
* DokuWiki Plugin prosemirror (Renderer Component)
|
||||
*
|
||||
@ -7,7 +9,6 @@
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
use dokuwiki\plugin\prosemirror\parser\ImageNode;
|
||||
use dokuwiki\plugin\prosemirror\parser\LocalLinkNode;
|
||||
use dokuwiki\plugin\prosemirror\parser\InternalLinkNode;
|
||||
@ -20,12 +21,6 @@ use dokuwiki\plugin\prosemirror\schema\Mark;
|
||||
use dokuwiki\plugin\prosemirror\schema\Node;
|
||||
use dokuwiki\plugin\prosemirror\schema\NodeStack;
|
||||
|
||||
if (!defined('DOKU_INC')) {
|
||||
die();
|
||||
}
|
||||
|
||||
require_once DOKU_INC . 'inc/parser/renderer.php';
|
||||
|
||||
class renderer_plugin_prosemirror extends Doku_Renderer
|
||||
{
|
||||
/** @var NodeStack */
|
||||
|
@ -87,7 +87,9 @@ class NodeStack
|
||||
$node = array_pop($this->stack);
|
||||
$this->stacklength--;
|
||||
if ($node->getType() != $type) {
|
||||
throw new \RuntimeException("Expected the current node to be of type $type found " . $node->getType() . " instead.");
|
||||
throw new \RuntimeException(
|
||||
"Expected the current node to be of type $type found " . $node->getType() . " instead."
|
||||
);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
Reference in New Issue
Block a user