1<?php 2/** 3 * The syntax plugin to handle <project-file> tags 4 * 5 */ 6 7require_once DOKU_PLUGIN . 'syntax.php'; 8 9class syntax_plugin_components_slice extends DokuWiki_Syntax_Plugin { 10 11 function getType() { 12 return 'substition'; 13 } 14 15 function getPType() { 16 return 'normal'; 17 } 18 19 function getSort() { 20 return 1; 21 } 22 23 function connectTo($mode) { 24 $this->Lexer->addSpecialPattern('<slice\b.*?/>', 25 $mode, 'plugin_components_slice'); 26 } 27 28 private function parse($tag) { 29 $xml = DOMDocument::loadXML($tag); 30 if ($xml == false) return NULL; 31 $attributes = array(); 32 foreach ($xml->firstChild->attributes as $attribute) 33 $attributes[$attribute->name] = $attribute->value; 34 return $attributes; 35 } 36 37 /** 38 * Handle the match 39 */ 40 function handle($match, $state, $pos, Doku_Handler $handler) { 41 switch ($state) { 42 case DOKU_LEXER_SPECIAL: 43 $attr = $this->parse($match); 44 if (!isset($attr['from']) || !$attr['from']) return false; 45 if (!isset($attr['to']) || !$attr['to']) return false; 46 global $ID; 47 $attr['id'] = $ID; 48 return $attr; 49 } 50 return false; 51 } 52 53 /** 54 * Create output 55 */ 56 function render($mode, Doku_Renderer $renderer, $data) { 57 if (!$data || $mode != 'xhtml') return; 58 $id = $data['id']; 59 $from = $data['from']; 60 $to = $data['to']; 61 $form = new Doku_Form(array('id' => "slice_$from_to", "class" => "wiki_slice_form")); 62 $form->addHidden('from', $from); 63 $form->addHidden('to', $to); 64 $form->addHidden('id', $id); 65 $form->addElement(form_makeButton('submit', '', "Slice $from--$to")); 66 $renderer->doc .= $form->getForm(); 67 } 68} 69