--- inc/global.php 2001/08/03 09:56:32 1.1.1.1
+++ inc/global.php 2001/09/25 15:38:04 1.13
@@ -1,41 +1,147 @@
[^\>]*\>)/e",
- "array_search(strtoupper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')",
- $str);
+
+ function MyUpper($str) {
+ return strtr(strtoupper($str), "¹ðèæ¾", "©ÐÈÆ®");
+ }
+
+ function MyLower($str) {
+ return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾");
+ }
+
+ function Letters() { return "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; }
+
+ function Slova($alpha_only = false) {
+ $sl = preg_split('//', Letters());
+ array_shift($sl); // First element is empty.
+ array_pop($sl); // Last element is empty.
+ if (!$alpha_only) array_unshift($sl, "@");
+ return $sl;
+ }
+
+ function MyCompare($a, $b) {
+ $slova = Letters();
+ $weights = "\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32";
+ return strcasecmp(strtr(MyUpper($a), $slova, $weights),
+ strtr(MyUpper($b), $slova, $weights));
+ }
+
+ 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 ParseNewline($str) {
- if (!$str) return $str;
- $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', '
', $str);
- $str = preg_replace('/\s*(\r\n|\n\r|\r|\n)/m', '
', $str);
+
+ function MyEscape($str, $full = true) {
+ $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD", "HR");
+ $str = preg_replace('/(^\s+|\s+$)/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('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str);
+ $str = preg_replace('/(class=normal)( class=normal)+/', '\\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 MyQuote($str) {
- global $dbh;
- if (!$dbh) return "'$str'";
- return $dbh->quote($str);
- }
- function MyMove($src, $dest) {
- $cmd = "mv -f '".EscapeShellCmd($src)."' '".EscapeShellCmd($dest)."'";
- return exec($cmd);
- }
- function MyDelete($src) {
- @unlink($src);
+
+ function ParseNewline($str, $paragraphs = false) {
+ if (!$str) return $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;
}
+
function error($msg) {
if (is_array($msg)) $msg = implode(" ", $msg);
- echo "
\n[".HTMLSpecialChars($msg).
- "]
\n";
+ echo "
\n[".HTMLSpecialChars($msg)."]
\n";
}
- function PicSize($pic) {
- global $syspicdir;
- $ret = array(0, 0);
- if ($pic) {
- @$size = GetImageSize($syspicdir."/".$pic);
- $ret = array($size[0], $size[1]);
- }
- return $ret;
+
+ function convert_html($str) {
+ $entities = array(
+ "nbsp" => " ", "#160" => " ", # nbsp
+ "amp" => " ", "#38" => " ", # amp
+ "quot" => "\"", "#34" => "\"", # quot
+ "lt" => "<", "#60" => "<", # lt
+ "gt" => ">", "#62" => ">", # gt
+ "Scaron" => "©", "#352" => "©",
+ "scaron" => "¹", "#353" => "¹",
+ "Ccaron" => "È", "#268" => "È", "#268" => "È",
+ "ccaron" => "è", "egrave" => "è", "#232" => "è", "#269" => "è",
+ "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
+ "cgrave" => "æ", "aelig" => "æ", "#230" => "æ", "#263" => "æ",
+ ">" => "Ð", "#272" => "Ð", "#" => "Ð",
+ ">" => "ð", "eth" => "ð", "#273" => "ð",
+ "Zcaron" => "®", "#381" => "®",
+ "zcaron" => "¾", "#382" => "¾",
+ );
+ # Skip if not a scalar
+ if (!is_string($str)) return $str;
+ # If a number, don't touch it
+ if (strcmp(intval($str)."", $str."") == 0) return $str;
+
+ # Replace "``" and "''" with """ (normal ASCII double quote)
+ $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 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 ""
+ $str = preg_replace('/\<\s*\//', '', $str);
+ # Do some wild exchanges...
+ $str = preg_replace('/(\<[ ]*(B|U|I)[^\>]*\>)[ ]*(\<\/[ ]*(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;
}
+
?>
|