/[health_html]/inc/global.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /inc/global.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (show annotations)
Wed Oct 10 12:40:58 2001 UTC (22 years, 6 months ago) by ravilov
Branch: MAIN
Changes since 1.16: +3 -1 lines
Improved Arhiva, Alergijski semafor and Home. Added a second Q&A page (test version). Other improvements & bugfixes.

1 <?php
2
3 function MyUpper($str) {
4 return strtr(strtoupper($str), "¹ðèæ¾", "©ÐÈÆ®");
5 }
6
7 function MyLower($str) {
8 return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾");
9 }
10
11 function Letters() { return "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; }
12
13 function Slova($alpha_only = false) {
14 $sl = preg_split('//', Letters());
15 array_shift($sl); // First element is empty.
16 array_pop($sl); // Last element is empty.
17 if (!$alpha_only) array_unshift($sl, "@");
18 return $sl;
19 }
20
21 function MyCompare($a, $b) {
22 $slova = Letters();
23 $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";
24 return strcasecmp(strtr(MyUpper($a), $slova, $weights),
25 strtr(MyUpper($b), $slova, $weights));
26 }
27
28 function my_replace($str, $start, $end, $pat = "", $rep = "") {
29 if (!$pat) $pat = '\s*(\r\n?|\n\r?)';
30 $idx1 = $idx2 = -1;
31 while (true) {
32 $str2 = strtoupper($str);
33 $idx1 = strpos($str2, $start, $idx1 + 1);
34 if ($idx1 === false) break;
35 $idx2 = strpos($str2, $end, $idx2 + 1);
36 if ($idx2 === false) break;
37 if ($idx1 > $idx2) break;
38 $idx2 += strlen($end);
39 $str1 = substr($str, 0, $idx1);
40 $str2 = preg_replace('/'.$pat.'/m', $rep,
41 substr($str, $idx1, $idx2 - $idx1));
42 $str3 = substr($str, $idx2, strlen($str) - $idx2);
43 $str = $str1.$str2.$str3;
44 }
45 return $str;
46 }
47
48 function MyEscape($str, $full = false) {
49 if ($full) {
50 $str = str_replace("&", "&amp;", $str);
51 $str = str_replace("<", "&lt;", $str);
52 $str = str_replace(">", "&gt;", $str);
53 }
54 $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD", "HR", "SUP", "SUB");
55 $str = preg_replace('/(^[ ]+|[ ]+$)/m', '', $str);
56 $str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'.
57 '\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str);
58 $str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str);
59 $str = preg_replace('/(target=_blank class=[^ ]+)( target=_blank class=[^ ]+)+/', '\\1', $str);
60 $str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str);
61 $str = preg_replace('/(class=[^ ]+)( class=[^ ]+)+/', '\\1', $str);
62 $str = my_replace($str, "<TABLE", "/TABLE>");
63 $str = my_replace($str, "<UL", "/UL>", true);
64 $str = my_replace($str, "<OL", "/OL>");
65 if (!$full) $str = my_replace($str, "<", ">", '"', "'|'");
66 $str = str_replace('"', "&quot;", $str);
67 if (!$full) $str = str_replace("'|'", '"', $str);
68 return $str;
69 }
70
71 function ParseNewline($str, $paragraphs = false) {
72 if (!$str) return $str;
73 $str = str_replace("\r\n", "\n", $str);
74 if ($paragraphs) $str = preg_replace('/[ ]*\n\n/s', ' </p><p class="ptext">', $str);
75 $str = preg_replace('/[ ]*\n/s', '<br>'."\n", $str);
76 return $str;
77 }
78
79 function error($msg) {
80 if (is_array($msg)) $msg = implode(" ", $msg);
81 echo "<BR>\n<FONT COLOR=\"#FF0000\">[".HTMLSpecialChars($msg)."]</FONT><BR>\n";
82 }
83
84 function convert_html($str) {
85 $entities = array(
86 "nbsp" => " ", "#160" => " ", # nbsp
87 "amp" => " ", "#38" => " ", # amp
88 "quot" => "\"", "#34" => "\"", # quot
89 "lt" => "<", "#60" => "<", # lt
90 "gt" => ">", "#62" => ">", # gt
91 "Scaron" => "©", "#352" => "©",
92 "scaron" => "¹", "#353" => "¹",
93 "Ccaron" => "È", "#268" => "È", "#268" => "È",
94 "ccaron" => "è", "egrave" => "è", "#232" => "è", "#269" => "è",
95 "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
96 "cgrave" => "æ", "aelig" => "æ", "#230" => "æ", "#263" => "æ",
97 "<?>" => "Ð", "#272" => "Ð", "#" => "Ð",
98 "<?>" => "ð", "eth" => "ð", "#273" => "ð",
99 "Zcaron" => "®", "#381" => "®",
100 "zcaron" => "¾", "#382" => "¾",
101 );
102 # Skip if not a scalar
103 if (!is_string($str)) return $str;
104 # If a number, don't touch it
105 if (strcmp(intval($str)."", $str."") == 0) return $str;
106
107 # Replace "``", "''", "<<" and ">>" with """ (normal ASCII double quote)
108 $str = str_replace("“", '"', $str);
109 $str = str_replace("”", '"', $str);
110 $str = str_replace("", '"', $str);
111 $str = str_replace("", '"', $str);
112 # Replace "-" with "-"
113 $str = str_replace("—", '-', $str);
114 # Replace character references ("&...;" and "&#...;") with its value
115 $str = preg_replace('/\&([^;]+);/em', '$entities["$1"]?$entities["$1"]:"?"', $str);
116 # Remove all whitespace from line beginnings and endings
117 $str = preg_replace('/(^[ ]+|[ ]+$)/s', '', $str);
118 # Remove "<P>[whitespace]</P>"
119 $str = preg_replace('/\<\s*P[^\>]*\>\s*\<\/\s*P\s*\>/im', "", $str);
120 # Replace "<BR>\n" with "\n"
121 $str = preg_replace('/\<[ ]*BR[^\>]*\>([\n\r]+)/im', '$1', $str);
122 # Replace "<P>" with "\n"
123 $str = preg_replace('/\<\s*P[^\>]*\>/im', "", $str);
124 # Replace "</P>" with "\n"
125 $str = preg_replace('/\<\/\s*P[^\>]*\>/im', "\n", $str);
126 # Replace "<BR>" with "\n"
127 $str = preg_replace('/\<BR\>/im', "\n", $str);
128 # Replace "<...>\n" with "\n<...>"
129 $str = preg_replace('/(\<[^\/][^\>]*\>)[ ]*([\r\n]*)[ ]*/m', '$2$1', $str);
130 # Replace "\n</...>" with "</...>\n"
131 $str = preg_replace('/[ ]*([\n\r]*)[ ]*(\<\/[^\>]+\>)/m', '$2$1', $str);
132 # Remove "<HEAD>" and "</HEAD>", and anything in between.
133 $str = preg_replace('/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims', '', $str);
134 # Remove all "<HTML>", "<HEAD>", "<BODY>" and "<FONT>" tags, along with their pairs
135 $str = preg_replace('/\<\/?\s*(HTML|HEAD|BODY|FONT|DIR)[^\>]*\>/im', '', $str);
136 # Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>")
137 #$str = preg_replace('/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im', '', $str);
138 # Replace "\n<LI>" or "<LI>\n" with "<LI>"
139 $str = preg_replace('/([ ]*[\r\n]*)(\<\/?\s*(LI|UL|OL)[ ]*\>)([ ]*[\r\n]*)/m', '$2', $str);
140 # Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively
141 $str = preg_replace('/(\<\s*(UL|OL)\s*\>)([ ]*(\r\n?|\n\r?))+/m', '$1', $str);
142 # Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively
143 $str = preg_replace('/([ ]*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m', '$3', $str);
144 # Replace "<[whitespace]/>" with "</"
145 $str = preg_replace('/\<\s*\//', '</', $str);
146 # Do some wild exchanges...
147 $str = preg_replace('/(\<[ ]*(B|U|I)[^\>]*\>)[ ]*(\<\/[ ]*(UL|OL|LI)[^\>]*\>)/', '$3$1', $str);
148 $str = preg_replace('/(\<[ ]*(UL|OL|LI)[^\>]*\>)[ ]*(\<\/[ ]*(B|U|I)[^\>]*\>)/', '$3$1', $str);
149 # Convert Win1250 to ISO8859-2
150 # (Actually, it should already be in ISO8859-2, but you never know.)
151 $str = strtr($str, "ŠÐÈƎšðèæž", "©ÐÈÆ®¹ðèæ¾");
152 return $str;
153 }
154
155 ?>

  ViewVC Help
Powered by ViewVC 1.1.26