45 |
return $str; |
return $str; |
46 |
} |
} |
47 |
|
|
48 |
function MyEscape($str, $full = true) { |
function MyEscape($str, $full = false) { |
49 |
|
if ($full) { |
50 |
|
$str = str_replace("&", "&", $str); |
51 |
|
$str = str_replace("<", "<", $str); |
52 |
|
$str = str_replace(">", ">", $str); |
53 |
|
} |
54 |
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD", "HR", "SUP", "SUB"); |
$allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD", "HR", "SUP", "SUB"); |
55 |
$str = preg_replace('/(^[ ]+|[ ]+$)/m', '', $str); |
$str = preg_replace('/(^[ ]+|[ ]+$)/m', '', $str); |
56 |
$str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. |
$str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'. |
57 |
'\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); |
'\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str); |
58 |
$str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str); |
if (!$full) { |
59 |
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
$str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str); |
60 |
$str = preg_replace('/(class=[^ ]+)( class=[^ ]+)+/', '\\1', $str); |
$str = preg_replace('/(\<\s*A\b)/i', '\\1 class=underlined target=_blank', $str); |
61 |
|
$str = preg_replace('/(class=[^ ]+)( class=[^ ]+)+/', '\\1', $str); |
62 |
|
$str = preg_replace('/(class=[^ ]+ target=_blank)( class=[^ ]+ target=_blank)+/', '\\1', $str); |
63 |
|
} |
64 |
$str = my_replace($str, "<TABLE", "/TABLE>"); |
$str = my_replace($str, "<TABLE", "/TABLE>"); |
65 |
$str = my_replace($str, "<UL", "/UL>", true); |
$str = my_replace($str, "<UL", "/UL>", true); |
66 |
$str = my_replace($str, "<OL", "/OL>"); |
$str = my_replace($str, "<OL", "/OL>"); |
106 |
# If a number, don't touch it |
# If a number, don't touch it |
107 |
if (strcmp(intval($str)."", $str."") == 0) return $str; |
if (strcmp(intval($str)."", $str."") == 0) return $str; |
108 |
|
|
109 |
# Replace "``" and "''" with """ (normal ASCII double quote) |
# Replace "``", "''", "<<" and ">>" with """ (normal ASCII double quote) |
110 |
$str = str_replace("“", '"', $str); |
$str = str_replace("“", '"', $str); |
111 |
$str = str_replace("”", '"', $str); |
$str = str_replace("”", '"', $str); |
112 |
|
$str = str_replace("¨", '"', $str); |
113 |
|
$str = str_replace("¯", '"', $str); |
114 |
# Replace "-" with "-" |
# Replace "-" with "-" |
115 |
$str = str_replace("—", '-', $str); |
$str = str_replace("—", '-', $str); |
116 |
# Replace character references ("&...;" and "&#...;") with its value |
# Replace character references ("&...;" and "&#...;") with its value |
154 |
return $str; |
return $str; |
155 |
} |
} |
156 |
|
|
157 |
|
function LinkIt($str) { |
158 |
|
$allowed = "ABCČčĘęDŠšEFGHIJKLMNOPQRS©¹TUVWXYZ®¾0123456789-_."; |
159 |
|
$idx = 0; |
160 |
|
while (true) { |
161 |
|
$idx = strpos($str, "@", $idx); |
162 |
|
if ($idx === false) break; |
163 |
|
$idx1 = $idx - 1; |
164 |
|
$idx2 = $idx + 1; |
165 |
|
while ($idx1 > 0 && stristr($allowed, $str[$idx1 - 1])) $idx1--; |
166 |
|
while ($idx2 < strlen($str) && stristr($allowed, $str[$idx2])) $idx2++; |
167 |
|
if ($idx2 > strlen($str)) $idx2 = strlen($str) - 1; |
168 |
|
if ($str[$idx2 - 1] == '.') $idx2--; |
169 |
|
$str1 = substr($str, 0, $idx1); |
170 |
|
$str2 = substr($str, $idx1, $idx2 - $idx1); |
171 |
|
$str3 = substr($str, $idx2, strlen($str)); |
172 |
|
$str4 = '<A HREF="mailto:'.$str2.'" CLASS="underlined">'.$str2.'</A>'; |
173 |
|
$str = $str1.$str4.$str3; |
174 |
|
$idx = $idx1 + strlen($str4); |
175 |
|
} |
176 |
|
return $str; |
177 |
|
} |
178 |
?> |
?> |