--- inc/global.php 2001/08/16 09:08:42 1.5
+++ inc/global.php 2001/09/19 12:23:56 1.11
@@ -1,47 +1,143 @@
[^\>]*\>)/e",
- "array_search(strtoupper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')",
- $str);
- $str = preg_replace("/(^\s+|\s+$)/", "", $str);
- $str = ereg_replace("\"", """, $str);
- return $str;
+ function MyUpper($str) {
+ return strtr(strtoupper($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 MyLower($str) {
+ return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾");
+ }
+
+ function Letters() { return "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; }
+
+ function Slova($alpha_only = false) {
+ $sl = preg_split('//', Letters());
+ array_pop($sl); // The final 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 nonl($str, $start, $end, $log = false) {
+ $idx1 = $idx2 = -1;
+ while (true) {
+ $idx1 = strpos(strtoupper($str), $start, $idx1 + 1);
+ $idx2 = strpos(strtoupper($str), $end, $idx2 + 1);
+ if ($idx1 === false) break;
+ if ($idx2 === false) break;
+ if ($idx1 > $idx2) break;
+ $idx2 += strlen($end);
+ $str = substr($str, 0, $idx1).preg_replace('/\s*(\r\n?|\n\r?)/m', '',
+ substr($str, $idx1, $idx2 - $idx1)).substr($str,
+ $idx2, strlen($str) - $idx2);
+if ($log) {
+echo "[$idx1] [$idx2]
\n";
+echo "1: [".substr($str, 0, $idx1)."]
\n";
+echo "2: [".substr($str, $idx1, $idx2 - $idx1)."]
\n";
+echo "3: [".substr($str, $idx2, strlen($str) - $idx2)."]
\n";
+}
+ }
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 MyEscape($str, $full = true) {
+ $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD");
+ $str = preg_replace("/(^\\s+|\\s+$)/", "", $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 = nonl($str, "
");
+ $str = nonl($str, "", true);
+ $str = nonl($str, "");
+ if (!$full) {
+ $idx1 = $idx2 = -1;
+ while (true) {
+ $idx1 = strpos($str, "<", $idx1 + 1);
+ $idx2 = strpos($str, ">", $idx2 + 1);
+ if ($idx1 === false) break;
+ if ($idx2 === false) break;
+ if ($idx1 > $idx2) break;
+ $str = substr($str, 0, $idx1).str_replace('"', "'|'",
+ substr($str, $idx1, $idx2 - $idx1)).substr($str,
+ $idx2, strlen($str) - $idx2);
+ }
+ }
+ $str = str_replace('"', """, $str);
+ if (!$full) $str = str_replace("'|'", '"', $str);
+ return $str;
}
- function MyDelete($src) {
- @unlink($src);
+
+ 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);
+ return nl2br($str);
}
+
function error($msg) {
if (is_array($msg)) $msg = implode(" ", $msg);
- 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;
+ echo "
\n[".HTMLSpecialChars($msg)."]
\n";
}
- function isEdit() {
- global $PHP_SELF;
- return stristr($PHP_SELF, "/edit/") ? true : false;
+
+ 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" => "è", "#232" => "è", "#269" => "è",
+ "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
+ "cgrave" => "æ", "#230" => "æ", "#263" => "æ",
+ "???" => "Ð", "#272" => "Ð", "#" => "Ð",
+ "???" => "ð", "#273" => "ð",
+ "Zcaron" => "®", "#381" => "®",
+ "zcaron" => "¾", "#382" => "¾",
+ );
+ $t = intval($str);
+ # 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 "
" 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 " " tags, along with their pairs
+ $str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str);
+ # Remove all table elements " ", "", "", " | ")
+ #$str = preg_replace("/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im", '', $str);
+ # " " and " " tags, along with their pairs
+ # 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 """ (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 at beginning or ending of a line
+ $str = preg_replace("/(^\s+|\s+$)/", '', $str);
+ # Convert Win1250 to ISO8859-2
+ $str = strtr($str, "ŠÐÈÆŽšðèæž", "©ÐÈÆ®¹ðèæ¾");
+ return $str;
}
?>
| |