/[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.11 - (hide annotations)
Wed Sep 19 12:23:56 2001 UTC (22 years, 8 months ago) by ravilov
Branch: MAIN
Changes since 1.10: +54 -11 lines
Added thefilez/med/ (PLIVAmed site). Other major changes...

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

  ViewVC Help
Powered by ViewVC 1.1.26