1<?php 2/* 3 * Plugin: inlineedit 4 * 5 * @license 6 * @author peterfromearth 7 */ 8 9if(!defined('DOKU_INC')) die(); 10 11/* 12 * All DokuWiki plugins to extend the parser/rendering mechanism 13 * need to inherit from this class 14 */ 15class syntax_plugin_inlineedit extends DokuWiki_Syntax_Plugin { 16 17 private $_itemPos = array(); 18 function incItemPos() { 19 global $ID; 20 if(array_key_exists($ID,$this->_itemPos)) { 21 return $this->_itemPos[$ID]++; 22 } else { 23 $this->_itemPos[$ID] = 1; 24 return 0; 25 } 26 } 27 function getItemPos(){ 28 global $ID; 29 if(array_key_exists($ID,$this->_itemPos)) { 30 $this->_itemPos[$ID]; 31 } else { 32 return 0; 33 } 34 } 35 36 /* 37 * What kind of syntax are we? 38 */ 39 function getType() { 40 return 'formatting'; 41 } 42 43 /* 44 * Where to sort in? 45 */ 46 function getSort() { 47 return 201; 48 } 49 50 /* 51 * Paragraph Type 52 */ 53 function getPType() { 54 return 'normal'; 55 } 56 57 function getAllowedTypes() { 58 return array( 59 'disabled' 60 ); 61 } 62 63 /** 64 * Connect pattern to lexer 65 */ 66 function connectTo($mode) { 67 $this->Lexer->addEntryPattern('<inlineedit>',$mode,'plugin_inlineedit'); 68 } 69 70 function postConnect() { 71 $this->Lexer->addExitPattern('</inlineedit>','plugin_inlineedit'); 72 } 73 74 /* 75 * Handle the matches 76 */ 77 function handle($match, $state, $pos, Doku_Handler $handler){ 78 global $ID; 79 80 $opts = array( 81 'pageid' => $ID, 82 ); 83 switch ($state) { 84 case DOKU_LEXER_ENTER : 85 $opts['itemPos']=$this->incItemPos(); 86 break; 87 case DOKU_LEXER_UNMATCHED : 88 $text = $match ? trim($match) : '...'; 89 $opts['text'] = $text; 90 break; 91 case DOKU_LEXER_EXIT : 92 break; 93 } 94 return array($state, $opts); 95 } 96 97 /* 98 * Create output 99 */ 100 function render($mode, Doku_Renderer $renderer, $data) 101 { 102 global $INFO; 103 104 list($state, $opts) = $data; 105 106 if($mode == 'xhtml' && $opts['pageid'] === $INFO['id']) { 107 108 switch ($state) { 109 case DOKU_LEXER_ENTER : 110 $itemPos = $opts['itemPos']; 111 $pageid = hsc($INFO['id']); 112 $renderer->doc .= "<span class='plugin__inlineedit' id='inlineedit_span_$itemPos' data-plugin-inlineedit-pageid='$pageid' data-plugin-inlineedit-itempos='$itemPos'>"; 113 break; 114 case DOKU_LEXER_UNMATCHED : 115 $text = $opts['text']; 116 if(!$text) $text = '...'; 117 $renderer->doc .= $renderer->_xmlEntities($text); 118 break; 119 case DOKU_LEXER_EXIT : 120 $renderer->doc .= "</span>"; 121 break; 122 } 123 } else { 124 if($state === DOKU_LEXER_UNMATCHED) { 125 $renderer->doc .= $opts['text']; 126 } 127 } 128 return true; 129 } 130 131} 132 133//Setup VIM: ex: et ts=4 enc=utf-8 : 134