HtmlDomRenderer.class.php
gehe zur Dokumentation dieser Datei00001 <?php
00002
00013 class HtmlDomRenderer
00014 {
00015 var $linkedObjectIds = array();
00016
00022 var $footnotes = array();
00023
00024 var $encodeHtml = false;
00025
00026 var $path = array();
00027
00028 var $domId = '';
00029
00030
00037 function renderElement( $child )
00038 {
00039 global $conf;
00040
00041 $this->path[] = $child;
00042
00043 $val = '';
00044
00045
00046
00047
00048
00049
00050 $attr = array();
00051 $praefix = '';
00052 $suffix = '';
00053 $empty = false;
00054
00055 if ( count($child->children) > 0 )
00056 {
00057 $subChild1 = $child->children[0];
00058
00059 if ( !empty($subChild1->class) )
00060 $attr['class'] = $subChild1->class;
00061
00062 if ( !empty($subChild1->style) )
00063 $attr['style'] = $subChild1->style;
00064
00065 if ( !empty($subChild1->title) )
00066 $attr['title'] = $subChild1->title;
00067 }
00068
00069 $praefix .= lang('TEXT_MARKUP_'.strtoupper(substr(get_class($child),0,-7)));
00070
00071 switch( strtolower(get_class($child)) )
00072 {
00073 case 'rawelement':
00074 $tag = '';
00075 $val = $child->src;
00076
00077 break;
00078
00079 case 'textelement':
00080 $tag = 'text';
00081
00082 $val .= $child->text;
00083
00084 break;
00085
00086
00087 case 'linkelement':
00088
00089 $tag = 'a';
00090 if ( !empty($child->name) )
00091 $attr['name'] = $child->name;
00092 else
00093 $attr['href'] = htmlspecialchars($child->getUrl());
00094
00095 if ( Object::available( $child->objectId ) )
00096 {
00097 $file = new File( $child->objectId );
00098 $file->load();
00099 $attr['title'] = $file->description;
00100 unset( $file );
00101 }
00102
00103 break;
00104
00105 case 'imageelement':
00106 $empty = true;
00107 $attr['alt'] = '';
00108
00109 if ( ! Object::available( $child->objectId ) )
00110 {
00111 $tag = '';
00112 }
00113 elseif ( empty($attr['title']) )
00114 {
00115 $tag = 'img';
00116 $attr['src'] = $child->getUrl();
00117 $attr['border'] = '0';
00118
00119
00120 $image = new File( $child->objectId );
00121
00122 $image->load();
00123 $attr['alt' ] = $image->name;
00124 $attr['title' ] = $image->description;
00125
00126 $image->getImageSize();
00127 $attr['width' ] = $image->width;
00128 $attr['height'] = $image->height;
00129 unset($image);
00130 }
00131 else
00132 {
00133 $tag = 'dl';
00134
00135 if ( empty($attr['class']) )
00136 $attr['class'] = "image";
00137
00138 $child->children = array();
00139 $dt = new DefinitionListItemElement();
00140 $dt->children[] = new TextElement('(image)');
00141 $dt->children[] = $child;
00142 $child->children[] = $dt;
00143
00144 $dd = new DefinitionListEntryElement();
00145 $dd->children[] = new TextElement('(image)');
00146 $dd->children[] = new TextElement($attr['title']);
00147 $child->children[] = $dd;
00148 }
00149 $suffix = '<img src="./themes/default/images/editor/image.png">';
00150 break;
00151
00152 case 'strongelement':
00153 $tag = 'strong';
00154 break;
00155
00156 case 'emphaticelement':
00157 $tag = 'em';
00158 break;
00159
00160 case 'insertedelement':
00161 $tag = 'ins';
00162 break;
00163
00164 case 'removedelement':
00165 $tag = 'del';
00166 break;
00167
00168 case 'headlineelement':
00169 $tag = 'h'.$child->level;
00170
00171 $l = new LinkElement();
00172 $l->name = $child->getName();
00173 $child->children[] = $l;
00174
00175 break;
00176
00177 case 'tableelement':
00178 $tag = 'table';
00179 break;
00180
00181 case 'tablelineelement':
00182 $tag = 'tr';
00183 break;
00184
00185 case 'definitionlistelement':
00186 $items = $child->children;
00187 $newChildren = array();
00188 foreach( $items as $item )
00189 {
00190 $def = new DefinitionItemElement();
00191 $def->key = $item->key;
00192 $item->key = '';
00193 $newChildren[] = $def;
00194 $newChildren[] = $item;
00195 }
00196
00197 $child->children = $newChildren;
00198 $tag = 'dl';
00199 break;
00200
00201 case 'definitionitemelement':
00202 if ( !empty($child->key) )
00203 {
00204 $tag = 'dt';
00205 $val = $child->key;
00206 }
00207 else
00208 {
00209 $tag = 'dd';
00210 }
00211 break;
00212
00213 case 'tablecellelement':
00214 if ( $child->isHeading )
00215 $tag = 'th'; else $tag = 'td';
00216
00217 if ( $child->rowSpan > 1 )
00218 $attr['rowspan'] = $child->rowSpan;
00219 if ( $child->colSpan > 1 )
00220 $attr['colspan'] = $child->colSpan;
00221 break;
00222
00223 case 'listelement':
00224 $tag = 'ul';
00225 break;
00226
00227 case 'teletypeelement':
00228 $tag = 'code';
00229 break;
00230
00231 case 'numberedlistelement':
00232 $tag = 'ol';
00233 break;
00234
00235 case 'listentryelement':
00236 $tag = 'li';
00237 break;
00238
00239 default:
00240
00241 }
00242
00243 $val = $this->renderValue($val);
00244 $val = $praefix.$val.$suffix;
00245
00246 if ( count($child->children)>0 )
00247 {
00248 $val .= '<ul>';
00249 foreach( $child->children as $c )
00250 {
00251 $val .= $this->renderElement( $c );
00252 }
00253 $val .= '</ul>';
00254 }
00255
00256
00257
00258 unset( $this->path[ count($this->path)-1 ] );
00259 return '<li>'.$val.'</li>';
00260 }
00261
00262
00263
00270 function renderValue( $value )
00271 {
00272 $val = ' <em>'.$value.'</em>';
00273 return $val;
00274 }
00275
00276
00277
00283 function render()
00284 {
00285 $this->renderedText = '';
00286 $this->footnotes = array();
00287
00288 foreach( $this->children as $child )
00289 $this->renderedText .= '<ul>'.$this->renderElement( $child ).'</ul>';
00290
00291 foreach( $this->footnotes as $child )
00292 $this->renderedText .= '<ul>'.$this->renderElement( $child ).'</ul>';
00293
00294 return $this->renderedText;
00295 }
00296
00297
00301 function getPathAsString()
00302 {
00303 $path = array();
00304 foreach( $this->path as $p )
00305 {
00306 $path[] = strtolower( substr(get_class($p),0,-7) );
00307 }
00308
00309 return implode('_',$path);
00310 }
00311 }
00312
00313 ?>