1<?php 2 3require_once DOKU_PLUGIN . 'odt/ODT/ODTDocument.php'; 4 5/** 6 * ODTFootnote: 7 * Class containing static code for handling footnotes. 8 * 9 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 10 * @author Andreas Gohr 11 */ 12class ODTFootnote 13{ 14 /** 15 * Open/start a footnote. 16 * 17 * All following content will go to the footnote instead of 18 * the document. To achieve this the previous content 19 * is moved to $store and $content is cleared 20 * 21 * @author Andreas Gohr <andi@splitbrain.org> 22 */ 23 function footnoteOpen(ODTInternalParams $params, $element=NULL, $attributes=NULL) { 24 // $element and $attributes are actually unused 25 26 // Move current content to store and record footnote 27 $params->document->store = $params->content; 28 $params->content = ''; 29 } 30 31 /** 32 * Close/end a footnote. 33 * 34 * All content is moved to the $footnotes array and the old 35 * content is restored from $store again. 36 * 37 * @author Andreas Gohr 38 */ 39 function footnoteClose(ODTInternalParams $params) { 40 // Recover footnote into the stack and restore old content 41 $footnote = $params->content; 42 $params->content = $params->document->store; 43 $params->document->store = ''; 44 45 // Check to see if this footnote has been seen before 46 $i = array_search($footnote, $params->document->footnotes); 47 $label = ($i+1).')'; 48 49 if ($i === false) { 50 $i = count($params->document->footnotes); 51 $label = ($i+1).')'; 52 53 // Its a new footnote, add it to the $footnotes array 54 $params->document->footnotes[$i] = $footnote; 55 56 $params->content .= '<text:note text:id="ftn'.$i.'" text:note-class="footnote">'; 57 $params->content .= '<text:note-citation text:label="'.$label.'">'.$label.'</text:note-citation>'; 58 $params->content .= '<text:note-body>'; 59 $params->content .= '<text:p text:style-name="'.$params->document->getStyleName('footnote').'">'; 60 $params->content .= $footnote; 61 $params->content .= '</text:p>'; 62 $params->content .= '</text:note-body>'; 63 $params->content .= '</text:note>'; 64 } else { 65 // Seen this one before - just reference it 66 $params->document->spanOpen($params->document->getStyleName('footnote anchor')); 67 $params->content .= '<text:note-ref text:note-class="footnote" text:reference-format="text" text:ref-name="ftn'.$i.'">'.$label.'</text:note-ref>'; 68 $params->document->spanClose(); 69 } 70 } 71} 72