B means B allowed in A '' => $xhtml_block, 'p' => $xhtml_inline."table,pre", 'pre' => $xhtml_inline, 'center' => $xhtml_inline, 'table' => 'caption,col,colgroup,thead,tfoot,tbody,tr', 'tbody' => 'tr', 'tr' => 'td,th', 'td' => $xhtml_inline.$xhtml_block, 'th' => $xhtml_inline.$xhtml_block, 'caption' => $xhtml_inline, 'dl2' => 'dt', 'listitem' => 'defkey,defval', 'ul' => 'li', 'ol' => 'li', 'dl' => 'dt,dd', 'li' => $xhtml_inline.$xhtml_block, 'dt' => $xhtml_inline, 'dd' => $xhtml_inline.$xhtml_block, 'h1' => $xhtml_inline, 'h2' => $xhtml_inline, 'h3' => $xhtml_inline, 'h4' => $xhtml_inline, 'h5' => $xhtml_inline, 'h6' => $xhtml_inline, 'font' => $xhtml_inline, 'div' => $xhtml_inline.$xhtml_block, 'blockquote' => $xhtml_block, ) ; $xhtml_allowed['caption'] .= $xhtml_allowed['p'] ; $xhtml_allowed['li'] .= $xhtml_allowed['p'] ; foreach ( $xhtml_allowed As $k => $v ) { $xhtml_allowed[$k] = explode ( ',' , $v ) ; } # The class class XML2XHTML { var $s = "" ; var $tags = array () ; var $ignore_counter = 0 ; var $links = array () ; function fix_text ( $s , $replace_amp = false ) { /* $s = html_entity_decode ( $s ) ; filter_named_entities ( $s ) ; $s = str_replace ( "&" , "&" , $s ) ; $s = str_replace ( "<" , "<" , $s ) ; $s = str_replace ( ">" , ">" , $s ) ; return utf8_decode ( $s ) ;*/ filter_named_entities ( $s ) ; if ( $replace_amp ) $s = str_replace ( "&" , "&" , $s ) ; $s = str_replace ( "<" , "<" , $s ) ; $s = str_replace ( ">" , ">" , $s ) ; return $s ; } function add ( $t ) { # Can be altered, e.g. for direct output (echo) $this->s .= $t ; } function is_allowed ( $tag , $base = "" ) { global $xhtml_allowed ; if ( $tag == "" ) return false ; if ( $base == "" ) { $o = $this->top_tag () ; $base = $o->tag ; } if ( !isset ( $xhtml_allowed[$base] ) ) return false ; return in_array ( $tag , $xhtml_allowed[$base] ) ; } function filter_evil_attributes ( $tag , &$attrs ) { if ( count ( $attrs ) == 0 ) return "" ; $ret = "" ; foreach ( $attrs AS $k => $v ) { $ret .= " " . strtolower ( $k ) . '="' . str_replace ( '"' , '\"' , $v ) . '"' ; } return $ret ; } function add_tag ( $tag , $attrs = array () , $bogus = false ) { $o->tag = $tag ; $o->really_open = $this->is_allowed ( $tag ) ; if ( $bogus ) $o->really_open = false ; $o->close_with_previous = false ; $this->tags[] = $o ; if ( $o->really_open ) $this->add ( "<{$tag}" . $this->filter_evil_attributes ( $tag , $attrs ) . ">" ) ; } function close_tag ( $tag ) { if ( $tag == '' ) return ; if ( count ( $this->tags ) == 0 ) die ( "CLOSING NON-OPEN TAG \"{$tag}\" (empty list)" ) ; $x = array_pop ( $this->tags ) ; if ( $tag != $x->tag ) die ( "CLOSING {$tag} instead of {$x->tag}" ) ; if ( $x->really_open ) $this->add ( "{$x->tag}>" ) ; # Auto-close previous? $o = $this->top_tag() ; if ( $o->close_with_previous ) { $this->close_tag ( $o->tag ) ; } } function insist_on ( $tag ) { global $xhtml_allowed ; $o = $this->top_tag () ; if ( $o->tag == $tag ) return ; # Everything OK foreach ( $xhtml_allowed AS $k => $v ) { if ( $o->tag != $k ) continue ; if ( in_array ( $tag , $v ) ) return ; # Everything OK } $o->tag = $tag ; $o->really_open = true ; $o->close_with_previous = true ; $this->tags[] = $o ; $this->add ( "<{$tag}>" ) ; } function top_tag () { if ( count ( $this->tags ) == 0 ) { $o->tag = "" ; $o->really_open = false ; $o->close_with_previous = false ; return $o ; } $x = array_pop ( $this->tags ) ; $this->tags[] = $x ; return $x ; } function tag_extension ( $open , &$attrs ) { if( !defined( 'MEDIAWIKI' ) ) return ; # Only as MediaWiki extension if ( $open ) { $this->extension_name = $attrs['EXTENSION_NAME'] ; $this->extension_attrs = $attrs ; unset ( $this->extension_attrs['EXTENSION_NAME'] ) ; $this->extension_text_before = $this->s ; $this->s = "" ; } else { $extension_text = trim ( $this->s ) ; $this->s = $this->extension_text_before ; $this->extension_text_before = "" ; global $wgParser , $wgTitle ; if ( !isset ( $wgParser ) ) return ; # Paranoia if ( !isset ( $wgParser->mTagHooks[$this->extension_name] ) ) return ; # Extension has no handler if ( $extension_text == "" ) $extension_text = "<{$this->extension_name}/>" ; else $extension_text = "<{$this->extension_name}>{$extension_text}{$this->extension_name}>" ; $options = new ParserOptions ; $s = $wgParser->parse ( $extension_text , $wgTitle , $options , false ) ; $this->add ( $s->getText() ) ; } } function tag_paragraph ( $open , &$attrs ) { global $xmlg ; if ( !isset ( $attrs['align'] ) AND $xmlg['xhtml_justify'] ) $attrs['align'] = 'justify' ; if ( $open ) $this->add_tag ( "p" , $attrs ) ; else $this->close_tag ( "p" ) ; } function tag_space ( $open , &$attrs ) { if ( $open ) $this->add ( " " ) ; } # SIMPLE TAGS function simple_tag ( $open , $tag ) { if ( $open ) $this->add_tag ( $tag ) ; else $this->close_tag ( $tag ) ; } function tag_bold ( $open , &$attrs ) { global $xmlg ; $this->simple_tag ( $open , $xmlg['xhtml_logical_markup'] ? "strong" : "b" ) ; } function tag_xhtml_b ( $open , &$attrs ) { $this->simple_tag ( $open , "b" ) ; } function tag_xhtml_strong ( $open , &$attrs ) { $this->simple_tag ( $open , "strong" ) ;} function tag_italics ( $open , &$attrs ) { global $xmlg ; $this->simple_tag ( $open , $xmlg['xhtml_logical_markup'] ? "em" : "i" ) ; } function tag_xhtml_i ( $open , &$attrs ) { $this->simple_tag ( $open , "i" ) ; } function tag_xhtml_em ( $open , &$attrs ) { $this->simple_tag ( $open , "em" ) ; } function tag_xhtml_ol ( $open , &$attrs ) { $this->simple_tag ( $open , "ol" ) ; } function tag_xhtml_ul ( $open , &$attrs ) { $this->simple_tag ( $open , "ul" ) ; } function tag_xhtml_li ( $open , &$attrs ) { $this->simple_tag ( $open , "li" ) ; } function tag_xhtml_dt ( $open , &$attrs ) { $this->simple_tag ( $open , "dt" ) ; } function tag_xhtml_dl ( $open , &$attrs ) { $this->simple_tag ( $open , "dl" ) ; } function tag_xhtml_dd ( $open , &$attrs ) { $this->simple_tag ( $open , "dd" ) ; } function tag_xhtml_code ( $open , &$attrs ) { $this->simple_tag ( $open , "code" ) ; } function tag_xhtml_pre ( $open , &$attrs ) { $this->simple_tag ( $open , "pre" ) ; } function tag_preblock ( $open , &$attrs ) { $this->simple_tag ( $open , "pre" ) ; } function tag_preline ( $open , &$attrs ) { if ( !$open ) $this->add ( "\n" ) ; } # MISC function tag_xhtml_font ( $open , &$attrs ) { if ( $open ) $this->add_tag ( "font" , $attrs ) ; else $this->close_tag ( "font" ) ; } function tag_defkey ( $open , &$attrs ) { $this->simple_tag ( $open , "defkey" ) ; } function tag_list ( $open , &$attrs ) { if ( !$open ) { $o = $this->top_tag () ; $this->close_tag ( $o->tag ) ; return ; } $type = $attrs['TYPE'] ; if ( $type == 'bullet' ) { $this->tag_xhtml_ul ( $open , $attrs ) ; } else if ( $type == 'numbered' ) { $this->tag_xhtml_ol ( $open , $attrs ) ; } else if ( $type == 'ident' ) { $this->tag_xhtml_dl ( $open , $attrs ) ; } else if ( $type == 'def' ) { $this->simple_tag ( $open , "dl2" ) ; $this->s = str_replace ( 'dl2>' , 'dl>' , $this->s ) ; } else return ; } # function tag_defkey ( $open , &$attrs ) { # if ( $open ) array_pop ( $this->tags ) ; # Remove dd # $this->tag_xhtml_dt ( $open , $attrs ) ; # } function tag_listitem ( $open , &$attrs ) { $o = $this->top_tag() ; if ( !$open ) { $this->close_tag ( $o->tag ) ; return ; } if ( $o->tag == 'dt' ) $this->tag_xhtml_dt ( $open , $attrs ) ; else if ( $o->tag == 'dl' ) $this->tag_xhtml_dd ( $open , $attrs ) ; else if ( $o->tag == 'dl2' ) $this->tag_xhtml_dt ( $open , $attrs ) ; else $this->tag_xhtml_li ( $open , $attrs ) ; } # HTML function tag_xhtml_div ( $open , &$attrs ) { if ( $open ) $this->add_tag ( "div" , $attrs ) ; else $this->close_tag ( "div" ) ; } function tag_xhtml_span ( $open , &$attrs ) { if ( $open ) $this->add_tag ( "div" , $attrs ) ; else $this->close_tag ( "div" ) ; } # LINKS function make_internal_link ( &$o ) { global $content_provider ; $text = $o->text ; if ( $text == "" ) $text = $o->target ; $text .= $o->trail ; $ns = $content_provider->get_namespace_id ( $o->target ) ; if ( $ns == 6 ) { # Image if ( !$content_provider->do_show_images () ) { return ; } $nstext = explode ( ":" , $o->target , 2 ) ; $target = array_pop ( $nstext ) ; $href = $content_provider->get_image_url ( $target ) ; list($i_width, $i_height, $i_type, $i_attr) = @getimagesize($href); if ( $i_width <= 0 ) { # Paranoia $i_width = 100 ; $i_height = 100 ; } $width = "" ; $align = "" ; $is_thumb = false ; foreach ( $o->parts AS $p ) { $p = strtolower ( trim ( $p ) ) ; if ( $p == 'thumb' ) { $is_thumb = true ; if ( $align == '' ) $align = 'right' ; if ( $width == '' ) $width = '200' ; } else if ( $p == 'right' || $p == 'center' || $p == 'left' ) { $align = $p ; } else if ( substr ( $p , -2 , 2 ) == 'px' ) { $width = trim ( substr ( $p , 0 , -2 ) ) ; } } if ( $width == '' ) { $size = "" ; $divwidth = "" ; } else { $height = ( $i_height * $width ) / $i_width ; $size = " width='{$width}' height='{$height}'" ; $divwidth = $width + 2 ; $divwidth = ";width={$divwidth}" ; } $s = "" ; $image_page = $content_provider->get_full_url ( $o->target ) ; if ( $is_thumb ) $s .= '