1<?php 2// must be run within Dokuwiki 3if(!defined('DOKU_INC')) die(); 4 5require_once(DOKU_PLUGIN.'formatplus2/formatting.php'); 6 7class syntax_plugin_formatplus2_blockdeleteplus extends FormattingPlus_Syntax_Plugin { 8 9 var $disabled = false; 10 var $no_classic = false; 11 12 function _getName() { 13 return 'BlockDelete+'; 14 } 15 function _getDesc() { 16 return 'Wraps text in <DEL> tags with optional meta-data. 17 Syntax: <del desc @date>...</del>'; 18 } 19 function _getConfig() { 20 return 'block_ins_del'; 21 } 22 23 function _getFormatting() { 24 return array(); 25 } 26 27 function getSort() { 28 return 86; 29 } 30 31 function getType() { 32 return 'container'; 33 } 34 35 function getAllowedTypes() { 36 return array('container','paragraphs','formatting','substition','disabled','protected'); 37 } 38 39 function getPType() { 40 return 'stack'; 41 } 42 43 function preConnect() { 44 if ($this->_disabledSyntax($this->_getConfig())) 45 $this->disabled = true; 46 if ($this->_disabledSyntax('classic_del')) 47 $this->no_classic = true; 48 } 49 50 function connectTo($mode) { 51 if (!$this->disabled) { 52 if (!$this->no_classic) { 53 $this->Lexer->addEntryPattern('<del>(?=.*</del>)', $mode, 'plugin_formatplus2_blockdeleteplus'); 54 } 55 $this->Lexer->addEntryPattern('<del [^>\r\n]+? @[^>\r\n]+?>(?=.*</del>)', $mode, 'plugin_formatplus2_blockdeleteplus'); 56 $this->Lexer->addEntryPattern('<del [^>\r\n]+?>(?=.*</del>)', $mode, 'plugin_formatplus2_blockdeleteplus'); 57 } 58 } 59 60 function postConnect() { 61 if (!$this->disabled) { 62 $this->Lexer->addExitPattern('</del>', 'plugin_formatplus2_blockdeleteplus'); 63 } 64 } 65 66 function handle($match, $state, $pos, Doku_Handler $handler){ 67 switch ($state) { 68 case DOKU_LEXER_ENTER: 69 $match = substr($match,4,-1); 70 if(!empty($match)){ 71 if(preg_match("/^(.*) =(.*?) @(.*?)$/", $match, $matches)){ 72 $output = array(trim($matches[1]),trim($matches[2]),trim($matches[3])); 73 }elseif(preg_match("/^(.*) @(.*?) =(.*?)$/", $match, $matches)){ 74 $output = array(trim($matches[1]),trim($matches[3]),trim($matches[2])); 75 }elseif(preg_match("/^(.*) =(.*?)$/", $match, $matches)){ 76 $output = array(trim($matches[1]),trim($matches[2]),''); 77 }elseif(preg_match("/^(.*) @(.*?)$/", $match, $matches)){ 78 $output = array(trim($matches[1]),'',trim($matches[2])); 79 }else{ 80 $output = array(trim($match),'',''); 81 } 82 }else{ 83 $output = array('','',''); 84 } 85 break; 86 case DOKU_LEXER_EXIT: 87 $output = ''; 88 break; 89 case DOKU_LEXER_UNMATCHED: 90 $output = $match; 91 break; 92 } 93 return array($state,$output); 94 } 95 96 function render($format, Doku_Renderer $renderer, $data) { 97 list($state,$output) = $data; 98 if (substr($format,0,5) == 'xhtml'){ 99 switch ($state) { 100 case DOKU_LEXER_ENTER: 101 $renderer->doc .= '<del class="block"'; 102 if(!empty($output[0])){ 103 $renderer->doc .= ' title="'.$renderer->_xmlEntities($output[0]).'"'; 104 } 105 if(!empty($output[1])){ 106 $renderer->doc .= ' cite="'.$renderer->_xmlEntities($output[1]).'"'; 107 } 108 if(!empty($output[2])){ 109 $renderer->doc .= ' datetime="'.$renderer->_xmlEntities($output[2]).'"'; 110 } 111 $renderer->doc .= '><div class="deleted">'.DOKU_LF; 112 break; 113 case DOKU_LEXER_EXIT: 114 $renderer->doc .= DOKU_LF.'</div></del>'.DOKU_LF; 115 break; 116 case DOKU_LEXER_UNMATCHED: 117 $renderer->doc .= $renderer->_xmlEntities($output); 118 break; 119 } 120 return true; 121 } elseif ($format == 'metadata') { 122 switch ($state) { 123 case DOKU_LEXER_ENTER: 124 $sp = ''; 125 $line = ''; 126 if(!empty($output[0])){ 127 $line .= '['.$output[0].']'; 128 $sp = ' '; 129 } 130 if(!empty($output[1])){ 131 $line .= $sp.$output[1]; 132 $sp = ' '; 133 } 134 if(!empty($output[2])){ 135 $line .= $sp.$output[2]; 136 } 137 if ($renderer->capture) 138 $renderer->doc .= $line; 139 break; 140 case DOKU_LEXER_EXIT: 141 if ($renderer->capture) { 142 $renderer->doc .= DOKU_LF; 143 if (strlen($renderer->doc) > 250) $renderer->capture = false; 144 } 145 break; 146 case DOKU_LEXER_UNMATCHED: 147 if ($renderer->capture) $renderer->doc .= $output; 148 break; 149 } 150 return true; 151 } 152 return false; 153 } 154 155} 156