1<?php 2/** 3 * ODT (Open Document format) export for Exttab3 plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Lars (LarsDW223) 7 * @author Thomas Schäfer <thomas.schaefer@itschert.net> 8 */ 9class helper_plugin_exttab3_odt extends DokuWiki_Plugin 10{ 11 public function render(Doku_Renderer $renderer, $data) 12 { 13 $properties = array(); 14 15 // Return if installed ODT plugin version is too old. 16 if ( method_exists($renderer, 'getODTProperties') == false 17 || method_exists($renderer, '_odtTableAddColumnUseProperties') == false 18 ) { 19 return false; 20 } 21 22 list($state, $tag, $attr) = $data; 23 24 // get style attribute 25 $style = ''; 26 if (preg_match('/style=".*"/', $attr, $matches) === 1) { 27 $style = substr($matches[0], 6); 28 $style = trim($style, ' "'); 29 } 30 31 // get rowspan attribute 32 $rowspan = 1; 33 if (preg_match('/rowspan[ ]*=[ ]*"([0-9]*)"/', $attr, $matches) === 1) { 34 $rowspan = $matches[1]; 35 } 36 37 // get colspan attribute 38 $colspan = 1; 39 if (preg_match('/colspan[ ]*=[ ]*"([0-9]*)"/', $attr, $matches) === 1) { 40 $colspan = $matches[1]; 41 } 42 43 // class to get CSS Properties by $render->getODTProperties() 44 $class = 'exttable'; 45 46 switch ($state) { 47 case DOKU_LEXER_ENTER: // open tag 48 if (!class_exists('ODTDocument')) { 49 // Code for backwards compatibility to older ODT versions 50 // Get CSS properties for ODT export. 51 $renderer->getODTProperties($properties, $tag, $class, $style); 52 53 switch ($tag) { 54 case 'table': 55 $renderer->_odtTableOpenUseProperties($properties); 56 break; 57 case 'caption': 58 // There is no caption in ODT table format. 59 // So we emulate it by creating a header row spaning over all columns. 60 $renderer->_odtTableRowOpenUseProperties($properties); 61 62 // Parameter 'colspan=0' indicates span across all columns! 63 $renderer->_odtTableHeaderOpenUseProperties($properties, 0, $rowspan); 64 break; 65 case 'th': 66 $renderer->_odtTableHeaderOpenUseProperties($properties); 67 $renderer->_odtTableAddColumnUseProperties($properties); 68 break; 69 case 'tr': 70 $renderer->_odtTableRowOpenUseProperties($properties); 71 break; 72 case 'td': 73 $renderer->_odtTableCellOpenUseProperties($properties); 74 break; 75 } 76 } else { 77 switch ($tag) { 78 case 'table': 79 $renderer->_odtTableOpenUseCSS(null, null, $tag, $attr); 80 break; 81 case 'caption': 82 // There is no caption in ODT table format. 83 // So we emulate it by creating a header row spaning over all columns. 84 $renderer->_odtTableRowOpenUseCSS($tag, $attr); 85 86 // Parameter 'colspan=0' indicates span across all columns! 87 $renderer->_odtTableHeaderOpenUseCSS(0, $rowspan, $tag, $attr); 88 break; 89 case 'th': 90 $renderer->_odtTableHeaderOpenUseCSS($colspan, $rowspan, $tag, $attr); 91 break; 92 case 'tr': 93 $renderer->_odtTableRowOpenUseCSS($tag, $attr); 94 break; 95 case 'td': 96 $renderer->_odtTableCellOpenUseCSS($colspan, $rowspan, $tag, $attr); 97 break; 98 } 99 } 100 break; 101 case DOKU_LEXER_MATCHED: // defensive, shouldn't occur 102 break; 103 case DOKU_LEXER_UNMATCHED: 104 $renderer->cdata($tag); 105 break; 106 case DOKU_LEXER_EXIT: // close tag 107 switch ($tag) { 108 case 'table': 109 //$renderer->table_close(); 110 $renderer->_odtTableClose(); 111 break; 112 case 'caption': 113 $renderer->tableheader_close(); 114 $renderer->tablerow_close(); 115 break; 116 case 'th': 117 $renderer->tableheader_close(); 118 break; 119 case 'tr': 120 $renderer->tablerow_close(); 121 break; 122 case 'td': 123 $renderer->p_close(); 124 $renderer->tablecell_close(); 125 break; 126 } 127 break; 128 } 129 } 130} 131