1<?php 2 3use ComboStrap\EditButton; 4use ComboStrap\ExceptionBadArgument; 5use ComboStrap\ExceptionNotEnabled; 6use ComboStrap\LogUtility; 7use ComboStrap\PluginUtility; 8use ComboStrap\Site; 9use ComboStrap\TagAttributes; 10 11 12/** 13 * 14 * An edit button 15 * 16 * This is created in the parse tree for the following reason 17 * 18 * * We need the start and end position (easier to catch at the parse tree creation because they are given in the handle function) 19 * * A component may not allow them (for instance: 20 * * an iterator will not allow edit button and delete them 21 * * or {@link syntax_plugin_combo_webcode} 22 * * The wiki id is mandatory and is given as global id in the handle function. In render, we may compose several parse tree (call stack) 23 * 24 */ 25class syntax_plugin_combo_edit extends DokuWiki_Syntax_Plugin 26{ 27 28 const TAG = "edit"; 29 const CANONICAL = self::TAG; 30 const START_POSITION = "start-position"; 31 const END_POSITION = "end-position"; 32 const LABEL = "label"; 33 const FORMAT = "format"; 34 const HEADING_ID = "heading-id"; 35 const SECTION_ID = "section-id"; // to be dokuwiki conform 36 37 38 /** 39 * Syntax Type. 40 * 41 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 42 * @see DokuWiki_Syntax_Plugin::getType() 43 */ 44 function getType(): string 45 { 46 return 'substition'; 47 } 48 49 /** 50 * How Dokuwiki will add P element 51 * 52 * * 'normal' - The plugin can be used inside paragraphs 53 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 54 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 55 * 56 * @see DokuWiki_Syntax_Plugin::getPType() 57 */ 58 function getPType(): string 59 { 60 return 'block'; 61 } 62 63 /** 64 * @return array 65 * Allow which kind of plugin inside 66 * 67 * Array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 68 * 69 * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 70 */ 71 function getAllowedTypes(): array 72 { 73 return array(); 74 } 75 76 77 function getSort(): int 78 { 79 return 201; 80 } 81 82 83 function connectTo($mode) 84 { 85 /** 86 * Call is generated via {@link EditButton::toComboCallComboFormat()} 87 */ 88 } 89 90 91 function postConnect() 92 { 93 94 /** 95 * Call is generated in {@link action_plugin_combo_instructionspostprocessing} 96 */ 97 98 } 99 100 function handle($match, $state, $pos, Doku_Handler $handler): array 101 { 102 103 return array(); 104 105 } 106 107 /** 108 * Render the output 109 * @param string $format 110 * @param Doku_Renderer $renderer 111 * @param array $data - what the function handle() return'ed 112 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 113 * @see DokuWiki_Syntax_Plugin::render() 114 * 115 * 116 */ 117 function render($format, Doku_Renderer $renderer, $data): bool 118 { 119 120 /** 121 * 122 * The rendering is used only when exporting to another format 123 * (XML) to render on another platform such as mobile 124 */ 125 if ($format !== "xhtml") { 126 return false; 127 } 128 129 $state = $data[PluginUtility::STATE]; 130 if ($state !== DOKU_LEXER_SPECIAL) { 131 LogUtility::error("The edit button should be a special tag", self::CANONICAL); 132 return false; 133 } 134 135 $editButton = EditButton::createFromCallStackArray($data[PluginUtility::ATTRIBUTES]); 136 try { 137 $renderer->doc .= $editButton->toHtmlComment(); 138 } catch (ExceptionBadArgument $e) { 139 LogUtility::error("Error while rendering the edit button ($editButton). Error: {$e->getMessage()}", self::CANONICAL); 140 return false; 141 } catch (ExceptionNotEnabled $e) { 142 // ok 143 return false; 144 } 145 return true; 146 147 } 148 149 150} 151 152