' ', "\n"=>"\n", "\r"=>"\r", "'"=>"'", '"'=>'"', '['=>'[', ']'=>']', '('=>'(', ';'=>';', ')'=>')', "\t"=>"\t", '='=>'=', '>'=>'>', '<'=>'<'); function fud_substr_replace($str, $newstr, $pos, $len) { return substr($str, 0, $pos).$newstr.substr($str, $pos+$len); } function url_check($url) { $url = preg_replace('!\s+!','', $url); if (strpos($url, '&#') !== false) { return preg_replace('!&#([0-9]{2,3});!e', "chr(\\1)", char_fix($url)); } return $url; } function tags_to_html($str, $allow_img=1, $no_char=0) { if (!$no_char) { $str = htmlspecialchars($str); } $str = nl2br($str); $ostr = ''; $pos = $old_pos = 0; while (($pos = strpos($str, '[', $pos)) !== false) { if (isset($GLOBALS['seps'][$str[$pos + 1]])) { ++$pos; continue; } if (($epos = strpos($str, ']', $pos)) === false) { break; } if (!($epos-$pos-1)) { $pos = $epos + 1; continue; } $tag = substr($str, $pos+1, $epos-$pos-1); if (($pparms = strpos($tag, '=')) !== false) { $parms = substr($tag, $pparms+1); if (!$pparms) { /*[= exception */ $pos = $epos+1; continue; } $tag = substr($tag, 0, $pparms); } else { $parms = ''; } $tag = strtolower($tag); switch ($tag) { case 'quote title': $tag = 'quote'; break; case 'list type': $tag = 'list'; break; case 'hr': $str{$pos} = '<'; $str{$pos+1} = 'h'; $str{$pos+2} = 'r'; $str{$epos} = '>'; continue 2; } if ($tag[0] == '/') { if (isset($end_tag[$pos])) { if( ($pos-$old_pos) ) $ostr .= substr($str, $old_pos, $pos-$old_pos); $ostr .= $end_tag[$pos]; $pos = $old_pos = $epos+1; } else { $pos = $epos+1; } continue; } $cpos = $epos; $ctag = '[/'.$tag.']'; $ctag_l = strlen($ctag); $otag = '['.$tag; $otag_l = strlen($otag); $rf = 1; $nt_tag = 0; while (($cpos = strpos($str, '[', $cpos)) !== false) { if (isset($end_tag[$cpos]) || isset($GLOBALS['seps'][$str[$cpos + 1]])) { ++$cpos; continue; } if (($cepos = strpos($str, ']', $cpos)) === false) { if (!$nt_tag) { break 2; } else { break; } } if (strcasecmp(substr($str, $cpos, $ctag_l), $ctag) == 0) { --$rf; } else if (strcasecmp(substr($str, $cpos, $otag_l), $otag) == 0) { ++$rf; } else { $nt_tag++; ++$cpos; continue; } if (!$rf) { break; } $cpos = $cepos; } if (!$cpos || ($rf && $str[$cpos] == '<')) { /* left over [ handler */ ++$pos; continue; } if ($cpos !== false) { if (($pos-$old_pos)) { $ostr .= substr($str, $old_pos, $pos-$old_pos); } switch ($tag) { case 'notag': $ostr .= ''.substr($str, $epos+1, $cpos-1-$epos).''; $epos = $cepos; break; case 'url': if (!$parms) { $url = substr($str, $epos+1, ($cpos-$epos)-1); } else { $url = $parms; } $url = url_check($url); if (!strncasecmp($url, 'www.', 4)) { $url = 'http://'. $url; } else if (strpos(strtolower($url), 'script:') !== false) { $ostr .= substr($str, $pos, $cepos - $pos + 1); $epos = $cepos; $str[$cpos] = '<'; break; } else { $url = str_replace('://', '://', $url); } $end_tag[$cpos] = ''; $ostr .= ''; break; case 'i': case 'u': case 'b': case 's': case 'sub': case 'sup': case 'del': $end_tag[$cpos] = ''; $ostr .= '<'.$tag.'>'; break; case 'email': if (!$parms) { $parms = str_replace('@', '@', substr($str, $epos+1, ($cpos-$epos)-1)); $ostr .= ''.$parms.''; $epos = $cepos; $str[$cpos] = '<'; } else { $end_tag[$cpos] = ''; $ostr .= ''; } break; case 'color': case 'size': case 'font': if ($tag == 'font') { $tag = 'face'; } $end_tag[$cpos] = ''; $ostr .= ''; break; case 'code': $param = substr($str, $epos+1, ($cpos-$epos)-1); $ostr .= '
'.reverse_nl2br($param).'
'; $epos = $cepos; $str[$cpos] = '<'; break; case 'pre': $param = substr($str, $epos+1, ($cpos-$epos)-1); $ostr .= '
'.reverse_nl2br($param).'
'; $epos = $cepos; $str[$cpos] = '<'; break; case 'php': $param = trim(reverse_fmt(reverse_nl2br(substr($str, $epos+1, ($cpos-$epos)-1)))); if (strncmp($param, '') { $param .= "\n?>"; } $ostr .= ''.trim(@highlight_string($param, true)).''; $epos = $cepos; $str[$cpos] = '<'; break; case 'img': case 'imgl': case 'imgr': if (!$allow_img) { $ostr .= substr($str, $pos, ($cepos-$pos)+1); } else { $class = ($tag == 'img') ? '' : 'class="'.$tag{3}.'" '; if (!$parms) { $parms = substr($str, $epos+1, ($cpos-$epos)-1); if (strpos(strtolower(url_check($parms)), 'script:') === false) { $ostr .= ''.$parms.''; } else { $ostr .= substr($str, $pos, ($cepos-$pos)+1); } } else { if (strpos(strtolower(url_check($parms)), 'script:') === false) { $ostr .= ''.substr($str, $epos+1, ($cpos-$epos)-1).''; } else { $ostr .= substr($str, $pos, ($cepos-$pos)+1); } } } $epos = $cepos; $str[$cpos] = '<'; break; case 'quote': if (!$parms) { $parms = '{TEMPLATE: post_quote}'; } else { $parms = str_replace(array('@',':'), array('@',':'), $parms); } $ostr .= '{TEMPLATE: post_html_quote_start}'; $end_tag[$cpos] = '{TEMPLATE: post_html_quote_end}'; break; case 'align': $end_tag[$cpos] = ''; $ostr .= '
'; break; case 'list': $tmp = substr($str, $epos, ($cpos-$epos)); $tmp_l = strlen($tmp); $tmp2 = str_replace(array('[*]'), array('
  • '), $tmp); $tmp2_l = strlen($tmp2); $str = str_replace($tmp, $tmp2, $str); $diff = $tmp2_l - $tmp_l; $cpos += $diff; if (isset($end_tag)) { foreach($end_tag as $key => $val) { if ($key < $epos) { continue; } $end_tag[$key+$diff] = $val; } } switch (strtolower($parms)) { case '1': case 'decimal': case 'a': $end_tag[$cpos] = ''; $ostr .= '
      '; break; case 'square': case 'circle': case 'disc': $end_tag[$cpos] = ''; $ostr .= '
        '; break; default: $end_tag[$cpos] = '
      '; $ostr .= '
        '; } break; case 'spoiler': $rnd = rand(); $end_tag[$cpos] = '
  • '; $ostr .= '
    ' .($parms ? $parms : '{TEMPLATE: post_proc_reveal_spoiler}').'