/[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.10 - (show annotations)
Fri Sep 7 15:07:17 2001 UTC (22 years, 7 months ago) by ravilov
Branch: MAIN
Changes since 1.9: +0 -1 lines
Modularized some pages. Some pages are now printable. Added a JavaScript date-checking module. Minor bugfixes.

1 <?php
2 function MyUpper($str) {
3 return strtr(strtoupper($str), "¹ðèæ¾", "©ÐÈÆ®");
4 }
5
6 function MyLower($str) {
7 return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾");
8 }
9
10 function Letters() { return "ABCÈÆDÐEFGHIJKLMNOPQRS©TUVWXYZ®"; }
11
12 function Slova($alpha_only = false) {
13 $sl = preg_split('//', Letters());
14 array_pop($sl); // The final element is empty.
15 if (!$alpha_only) array_unshift($sl, "@");
16 return $sl;
17 }
18
19 function MyCompare($a, $b) {
20 $slova = Letters();
21 $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 function MyEscape($str) {
27 $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI");
28 $str = preg_replace("/(^\\s+|\\s+$)/", "", $str);
29 $str = preg_replace("/(\\<\\/?\\s*(\\w+)\\b[^\\>]*\\>)/e", "array_search(MyUpper('\\2'),".
30 "\$allowed,false)?'\\1':HTMLSpecialChars('\\1')", $str);
31 $str = preg_replace("/(\\<\\s*[aA]\\b)/", '\\1 target=_blank class=more', $str);
32 $str = ereg_replace("\"", "&quot;", $str);
33 return $str;
34 }
35
36 function ParseNewline($str, $paragraphs = false) {
37 if (!$str) return $str;
38 if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', ' </p><p class="ptext">', $str);
39 $str = ereg_replace("[ \t]*(\r\n?|\n\r?)", '<br>', $str);
40 return $str;
41 }
42
43 function error($msg) {
44 if (is_array($msg)) $msg = implode(" ", $msg);
45 echo "<BR>\n<FONT COLOR=\"#FF0000\">[".HTMLSpecialChars($msg)."]</FONT><BR>\n";
46 }
47
48 function convert_html($str) {
49 $entities = array(
50 "nbsp" => " ", "#160" => " ", # nbsp
51 "amp" => " ", "#38" => " ", # amp
52 "quot" => "\"", "#34" => "\"", # quot
53 "lt" => "<", "#60" => "<", # lt
54 "gt" => ">", "#62" => ">", # gt
55 "Scaron" => "©", "#352" => "©",
56 "scaron" => "¹", "#353" => "¹",
57 "Ccaron" => "È", "#268" => "È", "#268" => "È",
58 "ccaron" => "è", "#232" => "è", "#269" => "è",
59 "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
60 "cgrave" => "æ", "#230" => "æ", "#263" => "æ",
61 "???" => "Ð", "#272" => "Ð", "#" => "Ð",
62 "???" => "ð", "#273" => "ð",
63 "Zcaron" => "®", "#381" => "®",
64 "zcaron" => "¾", "#382" => "¾",
65 );
66 $t = intval($str);
67 # Skip if not a scalar
68 if (!is_scalar($str)) return $str;
69 # If a number, don't touch it
70 if (strcmp(intval($str), $str) == 0) return $str;
71 # Replace "<BR>" with "\n"
72 $str = preg_replace("/\<BR\>/m", "\n", $str);
73 # Replace "<...>\n" with "<...>"
74 $str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str);
75 # Replace "\n</...>" with "</...>\n"
76 $str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str);
77 # Remove "<HEAD>"/"</HEAD>", and anything in between.
78 $str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str);
79 # Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<P>" and "BR" tags, along with their pairs
80 $str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str);
81 # Replace "\n<LI>" or "<LI>\n" with "<LI>"
82 $str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str);
83 # Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively
84 $str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str);
85 # Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively
86 $str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str);
87 # Replace "``" and "''" with """ (a single double quote)
88 $str = str_replace("“", '"', $str);
89 $str = str_replace("”", '"', $str);
90 # Replace "-" with "-"
91 $str = str_replace("—", '-', $str);
92 # Replace character references ("&...;" and "&#...;") with its value
93 $str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str);
94 # Remove all whitespace at beginning or ending of a line
95 $str = preg_replace("/(^\s+|\s+$)/", '', $str);
96 # Convert Win1250 to ISO8859-2
97 $str = strtr($str, "ŠÐÈƎšðèæž", "©ÐÈÆ®¹ðèæ¾");
98 return $str;
99 }
100 ?>

  ViewVC Help
Powered by ViewVC 1.1.26