tags; requires global $content_provider var $use_space_tag = true ; # Use instead of spaces before and after tags var $allowed = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 +-#:;.,%="\'\\' ; var $directhtmltags = array ( "b" => "xhtml:b", "i" => "xhtml:i", "u" => "xhtml:u", "s" => "xhtml:s", "p" => "xhtml:p", "br" => "xhtml:br", "em" => "xhtml:em", "div" => "xhtml:div", "span" => "xhtml:span", "big" => "xhtml:big", "small" => "xhtml:small", "sub" => "xhtml:sub", "sup" => "xhtml:sup", "font" => "xhtml:font", "center" => "xhtml:center", "table" => "xhtml:table", "tr" => "xhtml:tr", "th" => "xhtml:th", "td" => "xhtml:td", "pre" => "xhtml:pre", "code" => "xhtml:code", "caption" => "xhtml:caption", "cite" => "xhtml:cite", "ul" => "xhtml:ul", "ol" => "xhtml:ol", "li" => "xhtml:li", "tt" => "xhtml:tt", "h1" => "xhtml:h1", "h2" => "xhtml:h2", "h3" => "xhtml:h3", "h4" => "xhtml:h4", "h5" => "xhtml:h5", "h6" => "xhtml:h6", "h7" => "xhtml:h7", "h8" => "xhtml:h8", "h9" => "xhtml:h9", ) ; var $w ; # The wiki text var $wl ; # The wiki text length var $bold_italics ; var $tables = array () ; # List of open tables var $profile = array () ; # Some often used functions /** * Inherit settings from an existing parser */ function inherit ( &$base ) { $this->protocols = $base->protocols ; $this->errormessage = $base->errormessage ; $this->compensate_markup_errors = $base->compensate_markup_errors ; $this->auto_fill_templates = $base->auto_fill_templates ; $this->use_space_tag = $base->use_space_tag ; $this->compensate_markup_errors = $base->compensate_markup_errors ; $this->allowed = $base->allowed ; $this->directhtmltags = $base->directhtmltags ; } /** * Matches a function to the current text (default:once) */ function once ( &$a , &$xml , $f , $atleastonce = true , $many = false ) { $f = "p_{$f}" ; $cnt = 0 ; # print $f . " : " . htmlentities ( substr ( $this->w , $a , 20 ) ) . "
" ; flush () ; # if ( !isset ( $this->profile[$f] ) ) $this->profile[$f] = 0 ; # PROFILING do { # $this->profile[$f]++ ; # PROFILING $matched = $this->$f ( $a , $xml ) ; if ( $matched && $many ) $again = true ; else $again = false ; if ( $matched ) $cnt++ ; } while ( $again ) ; if ( !$atleastonce ) return true ; if ( $cnt > 0 ) return true ; return false ; } function onceormore ( &$a , &$xml , $f ) { return $this->once ( $a , $xml , $f , true , true ) ; } function nextis ( &$a , $t , $movecounter = true ) { if ( substr ( $this->w , $a , strlen ( $t ) ) != $t ) return false ; if ( $movecounter ) $a += strlen ( $t ) ; return true ; } function nextchar ( &$a , &$x ) { if ( $a >= $this->wl ) return false ; $x .= htmlspecialchars ( $this->w[$a] ) ; $a++ ; return true ; } function ischaracter ( $c ) { if ( $c >= 'A' && $c <= 'Z' ) return true ; if ( $c >= 'a' && $c <= 'z' ) return true ; return false ; } function skipblanks ( &$a , $blank = " " ) { while ( $a < $this->wl ) { if ( $this->w[$a] != $blank ) return ; $a++ ; } } ############## function p_internal_link_target ( &$a , &$xml , $closeit = "]]" ) { return $this->p_internal_link_text ( $a , $xml , true , $closeit ) ; } function p_internal_link_text2 ( &$a , &$xml , $closeit ) { $bi = $this->bold_italics ; $ret = $this->p_internal_link_text ( $a , $xml , false , $closeit , false ) ; if ( $closeit == ']]' && '' != $this->bold_italics ) $ret = false ; # Dirty hack to ensure good XML; FIXME!!! return $ret ; } function p_internal_link_text ( &$a , &$xml , $istarget = false , $closeit = "]]" , $mark = true ) { $b = $a ; $x = "" ; if ( $b >= $this->wl ) return false ; $bi = $this->bold_italics ; $this->bold_italics = '' ; $closeit1 = $closeit[0] ; while ( 1 ) { if ( $b >= $this->wl ) { $this->bold_italics = $bi ; return false ; } $c = $this->w[$b] ; if ( $closeit != "}}" && $c == "\n" ) { $this->bold_italics = $bi ; return false ; } if ( $c == "|" ) break ; if ( $c == $closeit1 && $this->nextis ( $b , $closeit , false ) ) break ; if ( !$istarget ) { if ( $c == "[" && $this->once ( $b , $x , "internal_link" ) ) continue ; if ( $c == "[" && $this->once ( $b , $x , "external_link" ) ) continue ; if ( $c == "{" && $this->once ( $b , $x , "template_variable" ) ) continue ; if ( $c == "{" && $this->once ( $b , $x , "template" ) ) continue ; if ( $c == "<" && $this->once ( $b , $x , "html" ) ) continue ; if ( $c == "'" && $this->p_bold ( $b , $x , "internal_link_text2" , $closeit ) ) { break ; } if ( $c == "'" && $this->p_italics ( $b , $x , "internal_link_text2" , $closeit ) ) { break ; } if ( $b + 10 < $this->wl && ( $this->w[$a+5] == '/' && $this->w[$a+7] == '/' ) && $this->once ( $b , $x , "external_freelink" ) ) continue ; } else { if ( $c == "{" && $this->once ( $b , $x , "template" ) ) continue ; } $x .= htmlspecialchars ( $c ) ; $b++ ; /* if ( $b >= $this->wl ) { $this->bold_italics = $bi ; return false ; }*/ } if ( $closeit == "}}" && !$istarget ) { $xml .= substr ( $this->w , $a , $b - $a ) ; $a = $b ; $this->bold_italics = $bi ; return true ; } $x = trim ( str_replace ( "\n" , "" , $x ) ) ; if ( $mark ) { if ( $istarget ) $xml .= "{$x}" ; else $xml .= "{$x}" ; } else $xml .= $x ; $a = $b ; $this->bold_italics = $bi ; return true ; } function p_internal_link_trail ( &$a , &$xml ) { $b = $a ; $x = "" ; while ( 1 ) { $c = "" ; if ( !$this->nextchar ( $b , $c ) ) break ; if ( $this->ischaracter ( $c ) ) { $x .= $c ; } else { $b-- ; break ; } } if ( $x == "" ) return false ; # No link trail $xml .= "{$x}" ; $a = $b ; return true ; } function p_internal_link ( &$a , &$xml ) { $x = "" ; $b = $a ; if ( !$this->nextis ( $b , "[[" ) ) return false ; if ( !$this->p_internal_link_target ( $b , $x , "]]" ) ) return false ; while ( 1 ) { if ( $this->nextis ( $b , "]]" ) ) break ; if ( !$this->nextis ( $b , "|" ) ) return false ; if ( !$this->p_internal_link_text ( $b , $x , false , "]]" ) ) return false ; } $this->p_internal_link_trail ( $b , $x ) ; $xml .= "{$x}" ; $a = $b ; return true ; } function p_magic_variable ( &$a , &$xml ) { $x = "" ; $b = $a ; if ( !$this->nextis ( $b , "__" ) ) return false ; $varname = "" ; for ( $c = $b ; $c < $this->wl && $this->w[$c] != '_' ; $c++ ) $varname .= $this->w[$c] ; if ( !$this->nextis ( $c , "__" ) ) return false ; $xml .= "{$varname}" ; $a = $c ; return true ; } # Template and template variable, utilizing parts of the internal link methods function p_template ( &$a , &$xml ) { global $content_provider , $xmlg ; if ( $xmlg["useapi"] ) return false ; # API already resolved templates $x = "" ; $b = $a ; if ( !$this->nextis ( $b , "{{" ) ) return false ; # if ( $this->nextis ( $b , "{" , false ) ) return false ; # Template names may not start with "{" if ( !$this->p_internal_link_target ( $b , $x , "}}" ) ) return false ; $target = $x ; $variables = array () ; $varnames = array () ; $vcount = 1 ; while ( 1 ) { if ( $this->nextis ( $b , "}}" ) ) break ; if ( !$this->nextis ( $b , "|" ) ) return false ; $l1 = strlen ( $x ) ; if ( !$this->p_internal_link_text ( $b , $x , false , "}}" ) ) return false ; $v = substr ( $x , $l1 ) ; $v = explode ( "=" , $v ) ; if ( count ( $v ) < 2 ) $vk = $vcount ; else { $vk = trim ( array_shift ( $v ) ) ; $varnames[$vcount] = $vk; } $vv = array_shift ( $v ) ; $variables[$vk] = $vv ; if ( !isset ( $variables[$vcount] ) ) $variables[$vcount] = $vv ; $vcount++ ; } $target = array_pop ( @explode ( ">" , $target , 2 ) ) ; $target = array_shift ( @explode ( "<" , $target , 2 ) ) ; if ( $this->auto_fill_templates == 'all' ) $replace_template = true ; else if ( $this->auto_fill_templates == 'none' ) $replace_template = false ; else { $found = in_array ( ucfirst ( $target ) , $this->template_list ) ; if ( $found AND $this->auto_fill_templates == 'these' ) $replace_template = true ; else if ( !$found AND $this->auto_fill_templates == 'notthese' ) $replace_template = true ; else $replace_template = false ; } if ( substr ( $target , 0 , 1 ) == '#' ) { # Try template logic $between = $this->process_template_logic ( $target , $variables ) ; # Change source (!) $w1 = substr ( $this->w , 0 , $a ) ; $w2 = substr ( $this->w , $b ) ; $this->w = $w1 . $between . $w2 ; $this->wl = strlen ( $this->w ) ; } else if ( $replace_template ) { # Do not generate