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

Diff of /inc/global.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by ravilov, Mon Sep 3 15:52:15 2001 UTC revision 1.19 by ravilov, Tue Oct 23 16:13:59 2001 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3          function MyUpper($str) {          function MyUpper($str) {
4                  return strtr(strtoupper($str), "", "Ʈ");                  return strtr(strtoupper($str), "", "Ʈ");
5          }          }
# Line 7  Line 8 
8                  return strtr(strtolower($str), "Ʈ", "");                  return strtr(strtolower($str), "Ʈ", "");
9          }          }
10    
11            function Letters() { return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
12    
13          function Slova($alpha_only = false) {          function Slova($alpha_only = false) {
14                  $sl = array("A", "B", "C", "", "", "D", "", "E", "F",                  $sl = preg_split('//', Letters());
15                          "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",                  array_shift($sl);       // First element is empty.
16                          "R", "S", "", "T", "U", "V", "W", "X", "Y", "Z", "");                  array_pop($sl);         // Last element is empty.
17                  if (!$alpha_only) array_unshift($sl, "@");                  if (!$alpha_only) array_unshift($sl, "@");
18                  return $sl;                  return $sl;
19          }          }
20    
21          function MyCompare($a, $b) {          function MyCompare($a, $b) {
22                  $slova = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";                  $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";                  $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),                  return strcasecmp(strtr(MyUpper($a), $slova, $weights),
25                          strtr(MyUpper($b), $slova, $weights));                          strtr(MyUpper($b), $slova, $weights));
26          }          }
27    
28          function MyEscape($str) {          function my_replace($str, $start, $end, $pat = "", $rep = "") {
29                  $allowed = array("", "B", "I", "U", "UL", "OL", "LI");                  if (!$pat) $pat = '\s*(\r\n?|\n\r?)';
30                  $str = preg_replace("/(\<\/?\s*(\w+)>[^\>]*\>)/e",                  $idx1 = $idx2 = -1;
31                          "array_search(MyUpper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')",                  while (true) {
32                          $str);                          $str2 = strtoupper($str);
33                  $str = preg_replace("/(^\s+|\s+$)/", "", $str);                          $idx1 = strpos($str2, $start, $idx1 + 1);
34                  $str = ereg_replace("\"", "&quot;", $str);                          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                    if (!$full) {
59                            $str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str);
60                            $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>");
65                    $str = my_replace($str, "<UL", "/UL>", true);
66                    $str = my_replace($str, "<OL", "/OL>");
67                    if (!$full) $str = my_replace($str, "<", ">", '"', "'|'");
68                    $str = str_replace('"', "&quot;", $str);
69                    if (!$full) $str = str_replace("'|'", '"', $str);
70                  return $str;                  return $str;
71          }          }
72    
73          function ParseNewline($str, $paragraphs = false) {          function ParseNewline($str, $paragraphs = false) {
74                  if (!$str) return $str;                  if (!$str) return $str;
75                  if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', ' </p><p class="ptext">', $str);                  $str = str_replace("\r\n", "\n", $str);
76                  $str = ereg_replace("[ \t]*(\r\n?|\n\r?)", '<br>', $str);                  if ($paragraphs) $str = preg_replace('/[        ]*\n\n/s', ' </p><p class="ptext">', $str);
77                    $str = preg_replace('/[         ]*\n/s', '<br>'."\n", $str);
78                  return $str;                  return $str;
79          }          }
80    
# Line 54  Line 93 
93                          "Scaron" => "", "#352" => "",                          "Scaron" => "", "#352" => "",
94                          "scaron" => "", "#353" => "",                          "scaron" => "", "#353" => "",
95                          "Ccaron" => "", "#268" => "", "#268" => "",                          "Ccaron" => "", "#268" => "", "#268" => "",
96                          "ccaron" => "", "#232" => "", "#269" => "",                          "ccaron" => "", "egrave" => "", "#232" => "", "#269" => "",
97                          "Cgrave" => "", "#262" => "", "#" => "",                          "Cgrave" => "", "#262" => "", "#" => "",
98                          "cgrave" => "", "#230" => "", "#263" => "",                          "cgrave" => "", "aelig" => "", "#230" => "", "#263" => "",
99                          "???" => "", "#272" => "", "#" => "",                          "<?>" => "", "#272" => "", "#" => "",
100                          "???" => "", "#273" => "",                          "<?>" => "", "eth" => "", "#273" => "",
101                          "Zcaron" => "", "#381" => "",                          "Zcaron" => "", "#381" => "",
102                          "zcaron" => "", "#382" => "",                          "zcaron" => "", "#382" => "",
103                  );                  );
                 $t = intval($str);  
104                  # Skip if not a scalar                  # Skip if not a scalar
105                  if (!is_scalar($str)) return $str;                  if (!is_string($str)) return $str;
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                  # Replace "<BR>" with "\n"  
109                  $str = preg_replace("/\<BR\>/m", "\n", $str);                  # Replace "``", "''", "<<" and ">>" with """ (normal ASCII double quote)
                 # Replace "<...>\n" with "<...>"  
                 $str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str);  
                 # Replace "\n</...>" with "</...>\n"  
                 $str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str);  
                 # Remove "<HEAD>"/"</HEAD>", and anything in between.  
                 $str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str);  
                 # Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<P>" and "BR" tags, along with their pairs  
                 $str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str);  
                 # Replace "\n<LI>" or "<LI>\n" with "<LI>"  
                 $str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str);  
                 # Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively  
                 $str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str);  
                 # Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively  
                 $str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str);  
                 # Replace "``" and "''" with """ (a single 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
117                  $str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str);                  $str = preg_replace('/\&([^;]+);/em', '$entities["$1"]?$entities["$1"]:"?"', $str);
118                  # Remove all whitespace at beginning or ending of a line                  # Remove all whitespace from line beginnings and endings
119                  $str = preg_replace("/(^\s+|\s+$)/", '', $str);                  $str = preg_replace('/(^[       ]+|[    ]+$)/s', '', $str);
120                    # Remove "<P>[whitespace]</P>"
121                    $str = preg_replace('/\<\s*P[^\>]*\>\s*\<\/\s*P\s*\>/im', "", $str);
122                    # Replace "<BR>\n" with "\n"
123                    $str = preg_replace('/\<[       ]*BR[^\>]*\>([\n\r]+)/im', '$1', $str);
124                    # Replace "<P>" with "\n"
125                    $str = preg_replace('/\<\s*P[^\>]*\>/im', "", $str);
126                    # Replace "</P>" with "\n"
127                    $str = preg_replace('/\<\/\s*P[^\>]*\>/im', "\n", $str);
128                    # Replace "<BR>" with "\n"
129                    $str = preg_replace('/\<BR\>/im', "\n", $str);
130                    # Replace "<...>\n" with "\n<...>"
131                    $str = preg_replace('/(\<[^\/][^\>]*\>)[        ]*([\r\n]*)[    ]*/m', '$2$1', $str);
132                    # Replace "\n</...>" with "</...>\n"
133                    $str = preg_replace('/[         ]*([\n\r]*)[    ]*(\<\/[^\>]+\>)/m', '$2$1', $str);
134                    # Remove "<HEAD>" and "</HEAD>", and anything in between.
135                    $str = preg_replace('/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims', '', $str);
136                    # Remove all "<HTML>", "<HEAD>", "<BODY>" and "<FONT>" tags, along with their pairs
137                    $str = preg_replace('/\<\/?\s*(HTML|HEAD|BODY|FONT|DIR)[^\>]*\>/im', '', $str);
138                    # Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>")
139                    #$str = preg_replace('/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im', '', $str);
140                    # Replace "\n<LI>" or "<LI>\n" with "<LI>"
141                    $str = preg_replace('/([        ]*[\r\n]*)(\<\/?\s*(LI|UL|OL)[  ]*\>)([         ]*[\r\n]*)/m', '$2', $str);
142                    # Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively
143                    $str = preg_replace('/(\<\s*(UL|OL)\s*\>)([     ]*(\r\n?|\n\r?))+/m', '$1', $str);
144                    # Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively
145                    $str = preg_replace('/([        ]*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m', '$3', $str);
146                    # Replace "<[whitespace]/>" with "</"
147                    $str = preg_replace('/\<\s*\//', '</', $str);
148                    # Do some wild exchanges...
149                    $str = preg_replace('/(\<[      ]*(B|U|I)[^\>]*\>)[     ]*(\<\/[        ]*(UL|OL|LI)[^\>]*\>)/', '$3$1', $str);
150                    $str = preg_replace('/(\<[      ]*(UL|OL|LI)[^\>]*\>)[  ]*(\<\/[        ]*(B|U|I)[^\>]*\>)/', '$3$1', $str);
151                  # Convert Win1250 to ISO8859-2                  # Convert Win1250 to ISO8859-2
152                    # (Actually, it should already be in ISO8859-2, but you never know.)
153                  $str = strtr($str, "Ǝ", "Ʈ");                  $str = strtr($str, "Ǝ", "Ʈ");
154                  return $str;                  return $str;
155          }          }
156    
157            function LinkIt($str) {
158                    $allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.";
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) - 1) $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  ?>  ?>

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.26