File modules/wikiparser/renderer/DocBookRenderer.class.php

Last commit: Sun Nov 1 03:08:55 2020 +0100	Jan Dankert	Replaced the calls to "Configuration::rawConfig()" with the OO style calls; Cleanup LoginAction.
1 <?php 2 3 namespace wikiparser\renderer; 4 use wikiparser\model\LinkElement; 5 use util\Text; 6 7 /** 8 * Renderer fuer das DOCBOOK-Format. 9 * 10 * Das Docbook-Format ist von der OASIS spezifiert und ermoeglicht die 11 * strukturierte Darstellung von Text-Dokumenten. 12 * 13 * Dieses Klasse erzeugt aus dem internen DOM-Baum ein DocBook-XML-Dokument. 14 * 15 * @author Jan Dankert, $Author$ 16 * @version $Revision$ 17 * @package openrat.text 18 */ 19 class DocBookRenderer 20 { 21 var $linkedObjectIds = array(); 22 var $encodeHtml = false; 23 24 25 /** 26 * Rendert ein Dokument-Element. 27 * 28 * @param Object $child Element 29 * @return String 30 */ 31 function renderElement($child) 32 { 33 $attr = array(); 34 $val = ''; 35 $praefix = ''; 36 $suffix = ''; 37 $empty = false; 38 39 switch (strtolower(get_class($child))) { 40 case 'macroelement': 41 $tag = ''; 42 break; 43 44 case 'tableofcontentelement': 45 $tag = 'toc'; 46 break; 47 48 case 'rawelement': 49 $tag = ''; 50 $val = $child->src; 51 52 break; 53 54 case 'textelement': 55 $tag = 'para'; 56 57 $val = $child->text; 58 $val = Text::encodeHtml($val); 59 $val = Text::replaceHtmlChars($val); 60 break; 61 62 case 'footnoteelement': 63 $tag = 'footnote'; 64 break; 65 66 case 'codeelement': 67 68 $tag = 'emphasis'; 69 $attr['role'] = 'code'; 70 break; 71 72 case 'quoteelement': 73 $tag = 'blockquote'; 74 break; 75 76 77 case 'paragraphelement': 78 $tag = 'para'; 79 break; 80 81 case 'speechelement': 82 $tag = 'citiation'; 83 break; 84 85 case 'linebreakelement': 86 $tag = ''; 87 $val = "\n"; 88 break; 89 90 case 'linkelement': 91 $tag = 'ulink'; 92 $attr['url'] = htmlspecialchars($child->getUrl()); 93 break; 94 95 case 'imageelement': 96 $empty = true; 97 $tag = 'graphic'; 98 $attr['fileref'] = $child->getUrl(); 99 break; 100 101 case 'strongelement': 102 $tag = 'emphasis'; 103 $attr['role'] = 'strong'; 104 break; 105 106 case 'emphaticelement': 107 $tag = 'emphasis'; 108 $attr['role'] = 'italic'; 109 break; 110 111 case 'insertedelement': 112 $tag = 'emphasis'; 113 $attr['role'] = 'inserted'; 114 break; 115 116 case 'removedelement': 117 $tag = 'emphasis'; 118 $attr['role'] = 'removed'; 119 break; 120 121 case 'headlineelement': 122 $tag = 'chapter'; // $child->level ? 123 124 $l = new LinkElement(); 125 $l->name = $child->getName(); 126 $child->children[] = $l; 127 128 break; 129 130 case 'tableelement': 131 $tag = 'table'; 132 break; 133 134 case 'tablelineelement': 135 $tag = 'row'; 136 break; 137 138 case 'definitionlistelement': 139 $tag = 'variablelist'; 140 break; 141 142 case 'definitionitemelement': 143 if (!empty($child->key)) { 144 $tag = 'listitem'; 145 $val = $child->key; 146 } else { 147 $tag = 'term'; 148 } 149 break; 150 151 case 'tablecellelement': 152 //if ( $child->isHeading ) 153 $tag = 'entry'; 154 break; 155 156 case 'listelement': 157 $tag = 'itemizedlist'; 158 break; 159 160 case 'teletypeelement': 161 $tag = 'emphasis'; 162 $attr['role'] = 'code'; 163 break; 164 165 case 'numberedlistelement': 166 $tag = 'orderedlist'; 167 break; 168 169 case 'listentryelement': 170 $tag = 'listitem'; 171 break; 172 173 default: 174 175 $tag = 'unknown-element'; 176 $attr['class'] = strtolower(get_class($child)); 177 break; 178 } 179 180 $val .= $praefix; 181 foreach ($child->children as $c) { 182 $val .= $this->renderElement($c); 183 } 184 185 $val .= $suffix; 186 return $this->renderXmlElement($tag, $val, $empty, $attr); 187 188 } 189 190 191 /** 192 * Erzeugt ein XML-Element. 193 * 194 * @param String $tag Name des Tags 195 * @param String $value Inhalt 196 * @param boolean $empty abk�rzen, wenn Inhalt leer ("<... />") 197 * @param Array $attr Attribute als Array<String,String> 198 * @return String 199 */ 200 function renderXmlElement($tag, $value, $empty, $attr = array()) 201 { 202 if ($tag == '') 203 return $value; 204 205 $val = '<' . $tag; 206 foreach ($attr as $attrName => $attrInhalt) { 207 $val .= ' ' . $attrName . '="' . $attrInhalt . '"'; 208 } 209 210 if ($value == '' && $empty) { 211 $val .= ' />'; 212 return $val; 213 } 214 215 $val .= '>' . $value . '</' . $tag . '>'; 216 return $val; 217 } 218 219 220 /** 221 * Rendering des Dokumentes.<br> 222 * 223 * @return String 224 */ 225 function render() 226 { 227 $this->renderedText = ''; 228 $this->renderedText .= '<?xml version="1.0" encoding="UTF-8" ?>'; 229 $this->renderedText .= '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">'; 230 231 foreach ($this->children as $child) 232 $this->renderedText .= $this->renderElement($child); 233 234 return $this->renderedText; 235 } 236 } 237 238 ?>
Download modules/wikiparser/renderer/DocBookRenderer.class.php
History Sun, 1 Nov 2020 03:08:55 +0100 Jan Dankert Replaced the calls to "Configuration::rawConfig()" with the OO style calls; Cleanup LoginAction. Sat, 26 Sep 2020 10:32:02 +0200 Jan Dankert Refactoring: No global $conf array any more. Sat, 22 Feb 2020 23:58:02 +0100 Jan Dankert Refactoring: Namespacing for module 'util'. Sat, 22 Feb 2020 22:45:05 +0100 Jan Dankert Refactoring: Enable Autoloading, Fix namespace structure. Sat, 16 Dec 2017 23:41:50 +0100 Jan Dankert Der Wikiparser als eigenes Modul (ehem. 'textclasses').