HtmlRenderer.class.php
gehe zur Dokumentation dieser Datei00001 <?php
00002
00013 class HtmlRenderer
00014 {
00015 var $linkedObjectIds = array();
00016 var $encodeHtml = false;
00017
00023 var $footnotes = array();
00024
00025
00032 function renderElement( $child )
00033 {
00034 global $conf;
00035
00036 $attr = array();
00037 $val = '';
00038 $praefix = '';
00039 $suffix = '';
00040 $empty = false;
00041
00042 if ( count($child->children) > 0 )
00043 {
00044 $subChild1 = $child->children[0];
00045
00046 if ( !empty($subChild1->class) )
00047 $attr['class'] = $subChild1->class;
00048
00049 if ( !empty($subChild1->style) )
00050 $attr['style'] = $subChild1->style;
00051
00052 if ( !empty($subChild1->title) )
00053 $attr['title'] = $subChild1->title;
00054 }
00055
00056 switch( strtolower(get_class($child)) )
00057 {
00058 case 'tableofcontentelement':
00059 $tag = 'p';
00060 foreach( $this->children as $h)
00061 {
00062 if ( strtolower(get_class($h))=='headlineelement' )
00063 {
00064 $child->children[] = new RawElement(str_repeat(' ',$h->level));
00065 $t = new TextElement( $h->getText() );
00066 $l = new LinkElement();
00067 $l->fragment=$h->getName();
00068 $l->children[] = $t;
00069 $child->children[] = $l;
00070 $child->children[] = new LineBreakElement();
00071 }
00072 }
00073 break;
00074
00075 case 'rawelement':
00076 $tag = '';
00077 $val = $child->src;
00078
00079 break;
00080
00081 case 'textelement':
00082 $tag = '';
00083
00084
00085 $val = $child->text;
00086 if ( $this->encodeHtml )
00087 $val = Text::encodeHtml( $val );
00088 $val = Text::replaceHtmlChars( $val );
00089 break;
00090
00091 case 'footnoteelement':
00092 $tag = 'a';
00093 $attr['href'] = '#footnote';
00094
00095 $title = '';
00096 foreach( $child->children as $c )
00097 $title .= $this->renderElement($c);
00098 $attr['title'] = strip_tags($title);
00099
00100 $nr = 1;
00101 foreach( $this->footnotes as $fn )
00102 if ( strtolower(get_class($fn))=='linebreakelement')
00103 $nr++;
00104
00105 $val = $nr;
00106 if ( @$conf['editor']['footnote']['bracket'])
00107 $val = '('.$nr.')';
00108 if ( @$conf['editor']['footnote']['sup'])
00109 $val = '<sup><small>'.$nr.'</small></sup>';
00110
00111
00112 if ( $nr == 1 )
00113 {
00114 $this->footnotes[] = new RawElement('—');
00115 $le = new LinkElement();
00116 $le->name = "footnote";
00117 $this->footnotes[] = $le;
00118 $this->footnotes[] = new RawElement('—');
00119 }
00120 $this->footnotes[] = new LineBreakElement();
00121 $this->footnotes[] = new RawElement($val);
00122 $this->footnotes[] = new RawElement(' ');
00123 foreach( $child->children as $c )
00124 $this->footnotes[] = $c;
00125
00126 $child->children = array();
00127
00128 break;
00129
00130 case 'codeelement':
00131
00132 if ( empty($child->language) )
00133
00134 $tag = 'pre';
00135 else
00136 {
00137
00138 $tag = '';
00139 $source = '';
00140 foreach( $child->children as $c )
00141 if ( strtolower(get_class($c)) == 'textelement')
00142 $source .= $c->text."\n";
00143 $child->children = array();
00144 require_once('./geshi/geshi.php');
00145 $geshi = new Geshi($source,$child->language);
00146 $val = $geshi->parse_code();
00147 }
00148 break;
00149
00150 case 'quoteelement':
00151 $tag = 'blockquote';
00152 break;
00153
00154
00155 case 'paragraphelement':
00156 $tag = 'p';
00157 break;
00158
00159 case 'speechelement':
00160 if ( isset($conf['editor']['html']['tag_speech']) )
00161 $tag = $conf['editor']['html']['tag_speech'];
00162 else
00163 $tag = 'cite';
00164
00165
00166
00167 $language = 'de';
00168 switch( $language )
00169 {
00170 case 'de':
00171 $praefix = '„';
00172 $suffix = '“';
00173 break;
00174 case 'fr':
00175 $praefix = '«';
00176 $suffix = '»';
00177 break;
00178 default:
00179 $praefix = '“';
00180 $suffix = '”';
00181 }
00182
00183 if ( $conf['editor']['html']['override_speech'] )
00184 {
00185 $praefix = $conf['editor']['html']['override_speech_open' ];
00186 $suffix = $conf['editor']['html']['override_speech_close'];
00187 }
00188 break;
00189
00190 case 'linebreakelement':
00191 $tag = 'br';
00192 $empty = true;
00193 break;
00194
00195 case 'linkelement':
00196 $tag = 'a';
00197 if ( !empty($child->name) )
00198 $attr['name'] = $child->name;
00199 else
00200 $attr['href'] = htmlspecialchars($child->getUrl());
00201
00202 if ( Object::available( $child->objectId ) )
00203 {
00204 $file = new File( $child->objectId );
00205 $file->load();
00206 $attr['title'] = $file->description;
00207 unset( $file );
00208 }
00209 break;
00210
00211 case 'imageelement':
00212 $empty = true;
00213 $attr['alt'] = '';
00214
00215 if ( ! Object::available( $child->objectId ) )
00216 {
00217 $tag = '';
00218 }
00219 elseif ( empty($attr['title']) )
00220 {
00221 $tag = 'img';
00222 $attr['src'] = $child->getUrl();
00223 $attr['border'] = '0';
00224
00225
00226 $image = new File( $child->objectId );
00227
00228 $image->load();
00229 $attr['alt' ] = $image->name;
00230 $attr['title' ] = $image->description;
00231
00232 $image->getImageSize();
00233 $attr['width' ] = $image->width;
00234 $attr['height'] = $image->height;
00235 unset($image);
00236 }
00237 else
00238 {
00239 $tag = 'dl';
00240
00241 if ( empty($attr['class']) )
00242 $attr['class'] = "image";
00243
00244 $child->children = array();
00245 $dt = new DefinitionListItemElement();
00246 $dt->children[] = new TextElement('(image)');
00247 $dt->children[] = $child;
00248 $child->children[] = $dt;
00249
00250 $dd = new DefinitionListEntryElement();
00251 $dd->children[] = new TextElement('(image)');
00252 $dd->children[] = new TextElement($attr['title']);
00253 $child->children[] = $dd;
00254 }
00255 break;
00256
00257 case 'strongelement':
00258 if ( isset($conf['editor']['html']['tag_strong']) )
00259 $tag = $conf['editor']['html']['tag_strong'];
00260 else
00261 $tag = 'strong';
00262 break;
00263
00264 case 'emphaticelement':
00265 if ( isset($conf['editor']['html']['tag_emphatic']) )
00266 $tag = $conf['editor']['html']['tag_emphatic'];
00267 else
00268 $tag = 'em';
00269 break;
00270
00271 case 'insertedelement':
00272 $tag = 'ins';
00273 break;
00274
00275 case 'removedelement':
00276 $tag = 'del';
00277 break;
00278
00279 case 'headlineelement':
00280 $tag = 'h'.$child->level;
00281
00282 $l = new LinkElement();
00283 $l->name = $child->getName();
00284 $child->children[] = $l;
00285
00286 break;
00287
00288 case 'tableelement':
00289 $tag = 'table';
00290 break;
00291
00292 case 'tablelineelement':
00293 $tag = 'tr';
00294 break;
00295
00296 case 'definitionlistelement':
00297 $items = $child->children;
00298 $newChildren = array();
00299 foreach( $items as $item )
00300 {
00301 $def = new DefinitionItemElement();
00302 $def->key = $item->key;
00303 $item->key = '';
00304 $newChildren[] = $def;
00305 $newChildren[] = $item;
00306 }
00307
00308 $child->children = $newChildren;
00309 $tag = 'dl';
00310 break;
00311
00312 case 'definitionitemelement':
00313 if ( !empty($child->key) )
00314 {
00315 $tag = 'dt';
00316 $val = $child->key;
00317 }
00318 else
00319 {
00320 $tag = 'dd';
00321 }
00322 break;
00323
00324 case 'tablecellelement':
00325 if ( $child->isHeading )
00326 $tag = 'th'; else $tag = 'td';
00327
00328 if ( $child->rowSpan > 1 )
00329 $attr['rowspan'] = $child->rowSpan;
00330 if ( $child->colSpan > 1 )
00331 $attr['colspan'] = $child->colSpan;
00332 break;
00333
00334 case 'listelement':
00335 $tag = 'ul';
00336 break;
00337
00338 case 'teletypeelement':
00339 if ( isset($conf['editor']['html']['tag_teletype']) )
00340 $tag = $conf['editor']['html']['tag_teletype'];
00341 else
00342 $tag = 'code';
00343 break;
00344
00345 case 'numberedlistelement':
00346 $tag = 'ol';
00347 break;
00348
00349 case 'listentryelement':
00350 $tag = 'li';
00351 break;
00352
00353 default:
00354
00355 $tag = 'unknown-element';
00356 $attr['class'] = strtolower(get_class($child));
00357 break;
00358 }
00359
00360 $val .= $praefix;
00361 foreach( $child->children as $c )
00362 {
00363 $val .= $this->renderElement( $c );
00364 }
00365
00366 $val .= $suffix;
00367
00368 return $this->renderHtmlElement($tag,$val,$empty,$attr);
00369
00370 }
00371
00372
00373
00383 function renderHtmlElement( $tag,$value,$empty,$attr=array() )
00384 {
00385 global $conf;
00386 if ( $tag == '' )
00387 return $value;
00388
00389 $val = '<'.$tag;
00390 foreach( $attr as $attrName=>$attrInhalt )
00391 {
00392 $val .= ' '.$attrName.'="'.$attrInhalt.'"';
00393 }
00394
00395 if ( $value == '' && $empty )
00396 {
00397
00398
00399
00400
00401 if ( $conf['editor']['html']['rendermode'] == 'xml' )
00402 {
00403 $val .= ' />';
00404 return $val;
00405 }
00406 else
00407 {
00408 $val .= '>';
00409 return $val;
00410 }
00411 }
00412
00413 $val .= '>'.$value.'</'.$tag.'>';
00414 return $val;
00415 }
00416
00417
00418
00424 function render()
00425 {
00426 $this->renderedText = '';
00427 $this->footnotes = array();
00428
00429 foreach( $this->children as $child )
00430 $this->renderedText .= $this->renderElement( $child );
00431
00432 foreach( $this->footnotes as $child )
00433 $this->renderedText .= $this->renderElement( $child );
00434
00435 return $this->renderedText;
00436 }
00437 }
00438
00439 ?>