1<?php 2 3/** 4 * @license See LICENSE file 5 * @author Jaap de Haan <jaap.dehaan@color-of-code.de> 6 */ 7 8// must be run within DokuWiki 9if (!defined('DOKU_INC')) { 10 die(); 11} 12 13if (!defined('DOKU_PLUGIN')) { 14 define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 15} 16 17require_once DOKU_PLUGIN . 'action.php'; 18 19// See help: https://www.dokuwiki.org/devel:toolbar 20// See help: https://www.dokuwiki.org/devel:section_editor 21 22class action_plugin_bpmnio extends DokuWiki_Action_Plugin 23{ 24 25 public function register(Doku_Event_Handler $controller) 26 { 27 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output'); 28 $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array()); 29 $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'handle_section_edit_button'); 30 } 31 32 /** 33 * Add <script> blocks to the meta headers 34 */ 35 public function handle_tpl_metaheader_output(Doku_Event &$event, $param) 36 { 37 38 $event->data['link'][] = $this->create_css("vendor/bpmn-js/dist/assets/diagram-js.css"); 39 $event->data['link'][] = $this->create_css("vendor/bpmn-js/dist/assets/bpmn-font/css/bpmn.css"); 40 $event->data['link'][] = $this->create_css("vendor/bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css"); 41 $event->data['link'][] = $this->create_css("vendor/bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css"); 42 43 // Load bpmn.io 44 $event->data['script'][] = $this->create_js("vendor/bpmn-js/dist/bpmn-viewer.production.min.js"); 45 46 // If activated we can edit but we cannot save 47 // $event->data['script'][] = $this->create_js("vendor/bpmn-js/dist/bpmn-modeler.production.min.js"); 48 $event->data['script'][] = $this->create_js("script.js"); 49 } 50 51 private function create_css($rel) 52 { 53 return array( 54 'type' => 'text/css', 55 'rel' => 'stylesheet', 56 'href' => $this->to_abs_url($rel), 57 ); 58 } 59 60 private function create_js($rel) 61 { 62 return array( 63 'type' => 'text/javascript', 64 'charset' => 'utf-8', 65 'src' => $this->to_abs_url($rel), 66 '_data' => '', 67 ); 68 } 69 70 private function to_abs_url($rel) 71 { 72 return DOKU_BASE . "lib/plugins/bpmnio/" . $rel; 73 } 74 75 public function handle_toolbar(Doku_Event $event, $param) 76 { 77 $event->data[] = array( 78 'type' => 'picker', 79 'title' => $this->getLang('picker'), 80 'icon' => '../../plugins/bpmnio/images/toolbar/picker.png', 81 'list' => array( 82 array( 83 'type' => 'format', 84 'title' => $this->getLang('add'), 85 'icon' => '../../plugins/bpmnio/images/toolbar/bpmn_add.png', 86 'open' => '<bpmnio zoom=1.0>\n' . $this->_get_open_text(), 87 'close' => $this->_get_close_text() . '\n</bpmnio>\n', 88 ), 89 ), 90 ); 91 } 92 93 public function handle_section_edit_button(Doku_Event $event, $param) 94 { 95 if ($event->data['target'] !== 'plugin_bpmnio') { 96 return; 97 } 98 $event->data['name'] = $this->getLang('section_name'); 99 } 100 101 private function _get_open_text() 102 { 103 return '<?xml version="1.0" encoding="UTF-8"?> 104<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="http://bpmn.io" exporterVersion="0.10.1"> 105 <collaboration id="Collaboration_1oh70al"> 106 <participant id="Participant_1r8g02m" name="'; 107 } 108 109 private function _get_close_text() 110 { 111 112 return '" processRef="Process_1" /> 113 </collaboration> 114 <process id="Process_1" isExecutable="false"> 115 <startEvent id="StartEvent_1" name="Start"> 116 <outgoing>SequenceFlow_1</outgoing> 117 </startEvent> 118 <task id="Task_1" name="Do Something"> 119 <incoming>SequenceFlow_1</incoming> 120 <incoming>SequenceFlow_121ul2c</incoming> 121 <incoming>SequenceFlow_0nuwads</incoming> 122 <outgoing>SequenceFlow_2</outgoing> 123 </task> 124 <exclusiveGateway id="ExclusiveGateway_1" name="Result OK" gatewayDirection="Diverging"> 125 <incoming>SequenceFlow_2</incoming> 126 <outgoing>SequenceFlow_0snv4kp</outgoing> 127 <outgoing>SequenceFlow_0nuwads</outgoing> 128 </exclusiveGateway> 129 <task id="Task_17knw8l" name="Monitor"> 130 <outgoing>SequenceFlow_121ul2c</outgoing> 131 </task> 132 <endEvent id="EndEvent_0oj7l6x" name="End"> 133 <incoming>SequenceFlow_0snv4kp</incoming> 134 </endEvent> 135 <sequenceFlow id="SequenceFlow_1" name="" sourceRef="StartEvent_1" targetRef="Task_1" /> 136 <sequenceFlow id="SequenceFlow_121ul2c" sourceRef="Task_17knw8l" targetRef="Task_1" /> 137 <sequenceFlow id="SequenceFlow_0nuwads" name="No" sourceRef="ExclusiveGateway_1" targetRef="Task_1" /> 138 <sequenceFlow id="SequenceFlow_2" sourceRef="Task_1" targetRef="ExclusiveGateway_1" /> 139 <sequenceFlow id="SequenceFlow_0snv4kp" name="Yes" sourceRef="ExclusiveGateway_1" targetRef="EndEvent_0oj7l6x" /> 140 </process> 141 <bpmndi:BPMNDiagram id="BpmnDiagram_1"> 142 <bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Collaboration_1oh70al"> 143 <bpmndi:BPMNShape id="Participant_1r8g02m_di" bpmnElement="Participant_1r8g02m"> 144 <omgdc:Bounds x="104" y="78" width="668" height="297" /> 145 </bpmndi:BPMNShape> 146 <bpmndi:BPMNShape id="StartEvent_1_gui" bpmnElement="StartEvent_1"> 147 <omgdc:Bounds x="242" y="187" width="30" height="30" /> 148 <bpmndi:BPMNLabel> 149 <omgdc:Bounds x="212" y="219" width="90" height="22" /> 150 </bpmndi:BPMNLabel> 151 </bpmndi:BPMNShape> 152 <bpmndi:BPMNShape id="Task_1_gui" bpmnElement="Task_1"> 153 <omgdc:Bounds x="340" y="162" width="100" height="80" /> 154 <bpmndi:BPMNLabel> 155 <omgdc:Bounds x="118.85714721679688" y="47" width="82.28570556640625" height="12" /> 156 </bpmndi:BPMNLabel> 157 </bpmndi:BPMNShape> 158 <bpmndi:BPMNShape id="ExclusiveGateway_1_gui" bpmnElement="ExclusiveGateway_1" isMarkerVisible="true"> 159 <omgdc:Bounds x="508" y="182" width="40" height="40" /> 160 <bpmndi:BPMNLabel> 161 <omgdc:Bounds x="483" y="234" width="90" height="24" /> 162 </bpmndi:BPMNLabel> 163 </bpmndi:BPMNShape> 164 <bpmndi:BPMNShape id="Task_17knw8l_di" bpmnElement="Task_17knw8l"> 165 <omgdc:Bounds x="340" y="275" width="100" height="80" /> 166 </bpmndi:BPMNShape> 167 <bpmndi:BPMNShape id="EndEvent_0oj7l6x_di" bpmnElement="EndEvent_0oj7l6x"> 168 <omgdc:Bounds x="648" y="184" width="36" height="36" /> 169 <bpmndi:BPMNLabel> 170 <omgdc:Bounds x="621" y="220" width="90" height="20" /> 171 </bpmndi:BPMNLabel> 172 </bpmndi:BPMNShape> 173 <bpmndi:BPMNEdge id="SequenceFlow_1_gui" bpmnElement="SequenceFlow_1"> 174 <omgdi:waypoint xsi:type="omgdc:Point" x="272" y="202" /> 175 <omgdi:waypoint xsi:type="omgdc:Point" x="340" y="202" /> 176 <bpmndi:BPMNLabel> 177 <omgdc:Bounds x="225" y="140" width="90" height="20" /> 178 </bpmndi:BPMNLabel> 179 </bpmndi:BPMNEdge> 180 <bpmndi:BPMNEdge id="SequenceFlow_121ul2c_di" bpmnElement="SequenceFlow_121ul2c"> 181 <omgdi:waypoint xsi:type="omgdc:Point" x="390" y="275" /> 182 <omgdi:waypoint xsi:type="omgdc:Point" x="390" y="242" /> 183 <bpmndi:BPMNLabel> 184 <omgdc:Bounds x="358" y="273" width="90" height="20" /> 185 </bpmndi:BPMNLabel> 186 </bpmndi:BPMNEdge> 187 <bpmndi:BPMNEdge id="SequenceFlow_0nuwads_di" bpmnElement="SequenceFlow_0nuwads"> 188 <omgdi:waypoint xsi:type="omgdc:Point" x="528" y="182" /> 189 <omgdi:waypoint xsi:type="omgdc:Point" x="528" y="110" /> 190 <omgdi:waypoint xsi:type="omgdc:Point" x="390" y="110" /> 191 <omgdi:waypoint xsi:type="omgdc:Point" x="390" y="162" /> 192 <bpmndi:BPMNLabel> 193 <omgdc:Bounds x="495" y="140" width="90" height="20" /> 194 </bpmndi:BPMNLabel> 195 </bpmndi:BPMNEdge> 196 <bpmndi:BPMNEdge id="SequenceFlow_2_di" bpmnElement="SequenceFlow_2"> 197 <omgdi:waypoint xsi:type="omgdc:Point" x="440" y="202" /> 198 <omgdi:waypoint xsi:type="omgdc:Point" x="508" y="202" /> 199 <bpmndi:BPMNLabel> 200 <omgdc:Bounds x="433" y="192" width="90" height="20" /> 201 </bpmndi:BPMNLabel> 202 </bpmndi:BPMNEdge> 203 <bpmndi:BPMNEdge id="SequenceFlow_0snv4kp_di" bpmnElement="SequenceFlow_0snv4kp"> 204 <omgdi:waypoint xsi:type="omgdc:Point" x="548" y="202" /> 205 <omgdi:waypoint xsi:type="omgdc:Point" x="648" y="202" /> 206 <bpmndi:BPMNLabel> 207 <omgdc:Bounds x="550" y="183" width="90" height="20" /> 208 </bpmndi:BPMNLabel> 209 </bpmndi:BPMNEdge> 210 </bpmndi:BPMNPlane> 211 </bpmndi:BPMNDiagram> 212</definitions>'; 213 } 214} 215