File modules/wikiparser/renderer/HtmlDomRenderer.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\DefinitionItemElement; 5 use DefinitionListEntryElement; 6 use DefinitionListItemElement; 7 use File; 8 use wikiparser\model\LinkElement; 9 use wikiparser\model\TextElement; 10 11 /** 12 * Dokument-Objekt.<br> 13 * Diese Objekt verk�rpert das Root-Objekt in einem DOM-Baum.<br> 14 * <br> 15 * Dieses Objekt kann Text parsen und seine Unterobjekte selbst erzeugen.<br> 16 * 17 * @author Jan Dankert, $Author$ 18 * @version $Revision$ 19 * @package openrat.text 20 */ 21 class HtmlDomRenderer 22 { 23 var $linkedObjectIds = array(); 24 25 /** 26 * Fu�noten. 27 * 28 * @var Array 29 */ 30 var $footnotes = array(); 31 32 var $encodeHtml = false; 33 34 var $path = array(); 35 36 var $domId = ''; 37 38 39 /** 40 * Rendert ein Dokument-Element. 41 * 42 * @param Object $child Element 43 * @return String 44 */ 45 function renderElement($child) 46 { 47 $this->path[] = $child; 48 49 $val = ''; 50 // $val = '<br/>'; 51 // foreach( $this->path as $p ) 52 // $val .= ' '; 53 54 // $val .= '<a href="#'.$this->getPathAsString().'">_</a>'; 55 56 $attr = array(); 57 $praefix = ''; 58 $suffix = ''; 59 $empty = false; 60 61 if (count($child->children) > 0) { 62 $subChild1 = $child->children[0]; 63 64 if (!empty($subChild1->class)) 65 $attr['class'] = $subChild1->class; 66 67 if (!empty($subChild1->style)) 68 $attr['style'] = $subChild1->style; 69 70 if (!empty($subChild1->title)) 71 $attr['title'] = $subChild1->title; 72 } 73 74 $praefix .= \cms\base\Language::lang('TEXT_MARKUP_' . strtoupper(substr(get_class($child), 0, -7))); 75 76 switch (strtolower(get_class($child))) { 77 case 'rawelement': 78 $tag = ''; 79 $val = $child->src; 80 81 break; 82 83 case 'textelement': 84 $tag = 'text'; 85 86 $val .= $child->text; 87 88 break; 89 90 91 case 'linkelement': 92 93 $tag = 'a'; 94 if (!empty($child->name)) 95 $attr['name'] = $child->name; 96 else 97 $attr['href'] = htmlspecialchars($child->getUrl()); 98 99 if (Object::available($child->objectId)) { 100 $file = new File($child->objectId); 101 $file->load(); 102 $attr['title'] = $file->description; 103 unset($file); 104 } 105 106 break; 107 108 case 'imageelement': 109 $empty = true; 110 $attr['alt'] = ''; 111 112 if (!Object::available($child->objectId)) { 113 $tag = ''; 114 } elseif (empty($attr['title'])) { 115 $tag = 'img'; 116 $attr['src'] = $child->getUrl(); 117 $attr['border'] = '0'; 118 119 // Breite/H�he des Bildes bestimmen. 120 $image = new File($child->objectId); 121 122 $image->load(); 123 $attr['alt'] = $image->name; 124 $attr['title'] = $image->description; 125 126 $image->getImageSize(); 127 $attr['width'] = $image->width; 128 $attr['height'] = $image->height; 129 unset($image); 130 } else { 131 $tag = 'dl'; 132 133 if (empty($attr['class'])) 134 $attr['class'] = "image"; 135 136 $child->children = array(); 137 $dt = new DefinitionListItemElement(); 138 $dt->children[] = new TextElement('(image)'); 139 $dt->children[] = $child; 140 $child->children[] = $dt; 141 142 $dd = new DefinitionListEntryElement(); 143 $dd->children[] = new TextElement('(image)'); 144 $dd->children[] = new TextElement($attr['title']); 145 $child->children[] = $dd; 146 } 147 $suffix = '<img src="./themes/default/images/editor/image.png">'; 148 break; 149 150 case 'strongelement': 151 $tag = 'strong'; 152 break; 153 154 case 'macroelement': 155 $tag = 'macro'; 156 $val = ucfirst($child->name); 157 break; 158 159 160 case 'emphaticelement': 161 $tag = 'em'; 162 break; 163 164 case 'insertedelement': 165 $tag = 'ins'; 166 break; 167 168 case 'removedelement': 169 $tag = 'del'; 170 break; 171 172 case 'headlineelement': 173 $tag = 'h' . $child->level; 174 175 $l = new LinkElement(); 176 $l->name = $child->getName(); 177 $child->children[] = $l; 178 179 break; 180 181 case 'tableelement': 182 $tag = 'table'; 183 break; 184 185 case 'tablelineelement': 186 $tag = 'tr'; 187 break; 188 189 case 'definitionlistelement': 190 $items = $child->children; 191 $newChildren = array(); 192 foreach ($items as $item) { 193 $def = new DefinitionItemElement(); 194 $def->key = $item->key; 195 $item->key = ''; 196 $newChildren[] = $def; 197 $newChildren[] = $item; 198 } 199 // Html::debug($newChildren,'Children-neu'); 200 $child->children = $newChildren; 201 $tag = 'dl'; 202 break; 203 204 case 'definitionitemelement': 205 if (!empty($child->key)) { 206 $tag = 'dt'; 207 $val = $child->key; 208 } else { 209 $tag = 'dd'; 210 } 211 break; 212 213 case 'tablecellelement': 214 if ($child->isHeading) 215 $tag = 'th'; else $tag = 'td'; 216 217 if ($child->rowSpan > 1) 218 $attr['rowspan'] = $child->rowSpan; 219 if ($child->colSpan > 1) 220 $attr['colspan'] = $child->colSpan; 221 break; 222 223 case 'listelement': 224 $tag = 'ul'; 225 break; 226 227 case 'teletypeelement': 228 $tag = 'code'; 229 break; 230 231 case 'numberedlistelement': 232 $tag = 'ol'; 233 break; 234 235 case 'listentryelement': 236 $tag = 'li'; 237 break; 238 239 default: 240 241 } 242 243 $val = $this->renderValue($val); 244 $val = '<div class="entry">' . $praefix . $val . $suffix . '</div>'; 245 246 if (count($child->children) > 0) { 247 $val .= '<ul class="tree">'; 248 foreach ($child->children as $c) { 249 $val .= $this->renderElement($c); 250 } 251 $val .= '</ul>'; 252 } 253 254 // echo "text:$val"; 255 256 unset($this->path[count($this->path) - 1]); 257 return '<li><div class="tree" />' . $val . '</li>'; 258 } 259 260 261 /** 262 * Rendert einen Inhalt. 263 * 264 * @param String $value Inhalt 265 * @return String 266 */ 267 function renderValue($value) 268 { 269 $val = ' <em>' . $value . '</em>'; 270 return $val; 271 } 272 273 274 /** 275 * Rendering des Dokumentes.<br> 276 * 277 * @return String 278 */ 279 function render() 280 { 281 $this->renderedText = ''; 282 $this->footnotes = array(); 283 284 $this->renderedText = '<ul class="tree">'; 285 286 foreach ($this->children as $child) 287 $this->renderedText .= '' . $this->renderElement($child) . ''; 288 //$this->renderedText .= '<li><div class="tree" /><div class="entry" /><ul class="tree">'.$this->renderElement( $child ).'</ul></li>'; 289 290 foreach ($this->footnotes as $child) 291 $this->renderedText .= '<li><div class="tree" /><div class="entry" /><ul class="tree">' . $this->renderElement($child) . '</ul></li>'; 292 $this->renderedText .= '</ul>'; 293 294 return $this->renderedText; 295 } 296 297 298 /** 299 * 300 */ 301 function getPathAsString() 302 { 303 $path = array(); 304 foreach ($this->path as $p) { 305 $path[] = strtolower(substr(get_class($p), 0, -7)); 306 } 307 308 return implode('_', $path); 309 } 310 } 311 312 ?>
Downloadmodules/wikiparser/renderer/HtmlDomRenderer.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, 26 Sep 2020 04:03:53 +0200 Jan Dankert Refactoring: read language keys with a class. 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').