--- inc/global.php 2001/09/03 15:52:15 1.8 +++ inc/global.php 2001/10/10 12:40:58 1.17 @@ -1,4 +1,5 @@ [^\>]*\>)/e", - "array_search(MyUpper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')", - $str); - $str = preg_replace("/(^\s+|\s+$)/", "", $str); - $str = ereg_replace("\"", """, $str); + function my_replace($str, $start, $end, $pat = "", $rep = "") { + if (!$pat) $pat = '\s*(\r\n?|\n\r?)'; + $idx1 = $idx2 = -1; + while (true) { + $str2 = strtoupper($str); + $idx1 = strpos($str2, $start, $idx1 + 1); + if ($idx1 === false) break; + $idx2 = strpos($str2, $end, $idx2 + 1); + if ($idx2 === false) break; + if ($idx1 > $idx2) break; + $idx2 += strlen($end); + $str1 = substr($str, 0, $idx1); + $str2 = preg_replace('/'.$pat.'/m', $rep, + substr($str, $idx1, $idx2 - $idx1)); + $str3 = substr($str, $idx2, strlen($str) - $idx2); + $str = $str1.$str2.$str3; + } + return $str; + } + + function MyEscape($str, $full = false) { + if ($full) { + $str = str_replace("&", "&", $str); + $str = str_replace("<", "<", $str); + $str = str_replace(">", ">", $str); + } + $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD", "HR", "SUP", "SUB"); + $str = preg_replace('/(^[ ]+|[ ]+$)/m', '', $str); + $str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. + '\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); + $str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str); + $str = preg_replace('/(target=_blank class=[^ ]+)( target=_blank class=[^ ]+)+/', '\\1', $str); + $str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); + $str = preg_replace('/(class=[^ ]+)( class=[^ ]+)+/', '\\1', $str); + $str = my_replace($str, ""); + $str = my_replace($str, "", true); + $str = my_replace($str, ""); + if (!$full) $str = my_replace($str, "<", ">", '"', "'|'"); + $str = str_replace('"', """, $str); + if (!$full) $str = str_replace("'|'", '"', $str); return $str; } function ParseNewline($str, $paragraphs = false) { if (!$str) return $str; - if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', '

', $str); - $str = ereg_replace("[ \t]*(\r\n?|\n\r?)", '
', $str); + $str = str_replace("\r\n", "\n", $str); + if ($paragraphs) $str = preg_replace('/[ ]*\n\n/s', '

', $str); + $str = preg_replace('/[ ]*\n/s', '
'."\n", $str); return $str; } @@ -54,46 +91,65 @@ "Scaron" => "", "#352" => "", "scaron" => "", "#353" => "", "Ccaron" => "", "#268" => "", "#268" => "", - "ccaron" => "", "#232" => "", "#269" => "", + "ccaron" => "", "egrave" => "", "#232" => "", "#269" => "", "Cgrave" => "", "#262" => "", "#" => "", - "cgrave" => "", "#230" => "", "#263" => "", - "???" => "", "#272" => "", "#" => "", - "???" => "", "#273" => "", + "cgrave" => "", "aelig" => "", "#230" => "", "#263" => "", + "" => "", "#272" => "", "#" => "", + "" => "", "eth" => "", "#273" => "", "Zcaron" => "", "#381" => "", "zcaron" => "", "#382" => "", ); - $t = intval($str); # Skip if not a scalar - if (!is_scalar($str)) return $str; + if (!is_string($str)) return $str; # If a number, don't touch it - if (strcmp(intval($str), $str) == 0) return $str; - # Replace "
" with "\n" - $str = preg_replace("/\/m", "\n", $str); - # Replace "<...>\n" with "<...>" - $str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str); - # Replace "\n" with "\n" - $str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str); - # Remove ""/"", and anything in between. - $str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str); - # Remove all "", "", "", "", "

" and "BR" tags, along with their pairs - $str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str); - # Replace "\n

  • " or "
  • \n" with "
  • " - $str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str); - # Replace "
      \n" or "
        \n" with "
          " or "
            ", respectively - $str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str); - # Replace "\n
        " or "\n
      " with "
    " or "", respectively - $str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str); - # Replace "``" and "''" with """ (a single double quote) + if (strcmp(intval($str)."", $str."") == 0) return $str; + + # Replace "``", "''", "<<" and ">>" with """ (normal ASCII double quote) $str = str_replace("", '"', $str); $str = str_replace("", '"', $str); + $str = str_replace("", '"', $str); + $str = str_replace("", '"', $str); # Replace "-" with "-" $str = str_replace("", '-', $str); # Replace character references ("&...;" and "&#...;") with its value - $str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str); - # Remove all whitespace at beginning or ending of a line - $str = preg_replace("/(^\s+|\s+$)/", '', $str); + $str = preg_replace('/\&([^;]+);/em', '$entities["$1"]?$entities["$1"]:"?"', $str); + # Remove all whitespace from line beginnings and endings + $str = preg_replace('/(^[ ]+|[ ]+$)/s', '', $str); + # Remove "

    [whitespace]

    " + $str = preg_replace('/\<\s*P[^\>]*\>\s*\<\/\s*P\s*\>/im', "", $str); + # Replace "
    \n" with "\n" + $str = preg_replace('/\<[ ]*BR[^\>]*\>([\n\r]+)/im', '$1', $str); + # Replace "

    " with "\n" + $str = preg_replace('/\<\s*P[^\>]*\>/im', "", $str); + # Replace "

    " with "\n" + $str = preg_replace('/\<\/\s*P[^\>]*\>/im', "\n", $str); + # Replace "
    " with "\n" + $str = preg_replace('/\/im', "\n", $str); + # Replace "<...>\n" with "\n<...>" + $str = preg_replace('/(\<[^\/][^\>]*\>)[ ]*([\r\n]*)[ ]*/m', '$2$1', $str); + # Replace "\n" with "\n" + $str = preg_replace('/[ ]*([\n\r]*)[ ]*(\<\/[^\>]+\>)/m', '$2$1', $str); + # Remove "" and "", and anything in between. + $str = preg_replace('/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims', '', $str); + # Remove all "", "", "" and "" tags, along with their pairs + $str = preg_replace('/\<\/?\s*(HTML|HEAD|BODY|FONT|DIR)[^\>]*\>/im', '', $str); + # Remove all table elements "", "", "
    ", "") + #$str = preg_replace('/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im', '', $str); + # Replace "\n
  • " or "
  • \n" with "
  • " + $str = preg_replace('/([ ]*[\r\n]*)(\<\/?\s*(LI|UL|OL)[ ]*\>)([ ]*[\r\n]*)/m', '$2', $str); + # Replace "
      \n" or "
        \n" with "
          " or "
            ", respectively + $str = preg_replace('/(\<\s*(UL|OL)\s*\>)([ ]*(\r\n?|\n\r?))+/m', '$1', $str); + # Replace "\n
        " or "\n
      " with "
    " or "", respectively + $str = preg_replace('/([ ]*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m', '$3', $str); + # Replace "<[whitespace]/>" with "]*\>)[ ]*(\<\/[ ]*(UL|OL|LI)[^\>]*\>)/', '$3$1', $str); + $str = preg_replace('/(\<[ ]*(UL|OL|LI)[^\>]*\>)[ ]*(\<\/[ ]*(B|U|I)[^\>]*\>)/', '$3$1', $str); # Convert Win1250 to ISO8859-2 + # (Actually, it should already be in ISO8859-2, but you never know.) $str = strtr($str, "Ǝ", "Ʈ"); return $str; } + ?>