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 $note = new ODTElementNote(); 31 $params->document->state->enter($note); 32 $note->setHTMLElement ($element); 33 } 34 35 /** 36 * Close/end a footnote. 37 * 38 * All content is moved to the $footnotes array and the old 39 * content is restored from $store again. 40 * 41 * @author Andreas Gohr 42 */ 43 function footnoteClose(ODTInternalParams $params) { 44 // Close any open paragraph first 45 $params->document->paragraphClose(); 46 47 ODTUtility::closeHTMLElement ($params, $params->document->state->getHTMLElement()); 48 $params->document->closeCurrentElement(); 49 50 // Recover footnote into the stack and restore old content 51 $footnote = $params->content; 52 $params->content = $params->document->store; 53 $params->document->store = ''; 54 55 // Check to see if this footnote has been seen before 56 $i = array_search($footnote, $params->document->footnotes); 57 $label = ($i+1).')'; 58 59 if ($i === false) { 60 $i = count($params->document->footnotes); 61 $label = ($i+1).')'; 62 63 // Its a new footnote, add it to the $footnotes array 64 $params->document->footnotes[$i] = $footnote; 65 66 $params->content .= '<text:note text:id="ftn'.$i.'" text:note-class="footnote">'; 67 $params->content .= '<text:note-citation text:label="'.$label.'">'.$label.'</text:note-citation>'; 68 $params->content .= '<text:note-body>'; 69 $params->content .= $footnote; 70 $params->content .= '</text:note-body>'; 71 $params->content .= '</text:note>'; 72 } else { 73 // Seen this one before - just reference it 74 $params->document->spanOpen($params->document->getStyleName('footnote anchor')); 75 $params->content .= '<text:note-ref text:note-class="footnote" text:reference-format="text" text:ref-name="ftn'.$i.'">'.$label.'</text:note-ref>'; 76 $params->document->spanClose(); 77 } 78 79 // Only for debugging... 80 //$params->document->trace_dump .= $params->document->state->toString(); 81 } 82} 83