/[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

Annotation of /inc/global.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations)
Tue Oct 2 16:18:09 2001 UTC (22 years, 6 months ago) by ravilov
Branch: MAIN
Changes since 1.14: +1 -1 lines
Users can now pick their username/password on registration (PLIVAmed). Other bugfixes.

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

  ViewVC Help
Powered by ViewVC 1.1.26