/[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.7 by ravilov, Thu Aug 30 16:35:36 2001 UTC revision 1.11 by ravilov, Wed Sep 19 12:23:56 2001 UTC
# Line 1  Line 1 
1  <?php  <?php
2          function MyEscape($str) {          function MyUpper($str) {
3                  $allowed = array("", "B", "I", "U", "UL", "OL", "LI");                  return strtr(strtoupper($str), "¹ðèæ¾", "©ÐÈÆ®");
4                  $str = preg_replace("/(\<\/?\s*(\w+)>[^\>]*\>)/e",          }
5                          "array_search(strtoupper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')",  
6                          $str);          function MyLower($str) {
7                  $str = preg_replace("/(^\s+|\s+$)/", "", $str);                  return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾");
8                  $str = ereg_replace("\"", "&quot;", $str);          }
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 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;                  return $str;
46          }          }
47    
48          function ParseNewline($str, $paragraphs = false) {          function MyEscape($str, $full = true) {
49                  if (!$str) return $str;                  $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD");
50                  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 = preg_replace("/(^\\s+|\\s+$)/", "", $str);
51                  $str = ereg_replace("[ \t]*(\r\n?|\n\r?)", '<br>', $str);                  $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                  return $str;                  return $str;
74          }          }
75    
76          function Slova() {          function ParseNewline($str, $paragraphs = false) {
77                  return array("@", "A", "B", "C", "È", "Æ", "D", "Ð", "E", "F",                  if (!$str) return $str;
78                          "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",                  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                          "R", "S", "©", "T", "U", "V", "W", "X", "Y", "Z", "®");                  return nl2br($str);
80          }          }
81    
82          function error($msg) {          function error($msg) {
# Line 36  Line 93 
93                          "gt" => ">", "#62" => ">",      # gt                          "gt" => ">", "#62" => ">",      # gt
94                          "Scaron" => "©", "#352" => "©",                          "Scaron" => "©", "#352" => "©",
95                          "scaron" => "¹", "#353" => "¹",                          "scaron" => "¹", "#353" => "¹",
96                          "Ccaron" => "È", "#" => "È", "#268" => "È",                          "Ccaron" => "È", "#268" => "È", "#268" => "È",
97                          "ccaron" => "è", "#232" => "è", "#269" => "è",                          "ccaron" => "è", "#232" => "è", "#269" => "è",
98                          "Cgrave" => "Æ", "#" => "Æ", "#" => "Æ",                          "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
99                          "cgrave" => "æ", "#230" => "æ", "#263" => "æ",                          "cgrave" => "æ", "#230" => "æ", "#263" => "æ",
100                          "?" => "Ð", "#" => "Ð", "#" => "Ð",                          "???" => "Ð", "#272" => "Ð", "#" => "Ð",
101                          "?" => "ð", "#" => "ð", "#273" => "ð",                          "???" => "ð", "#273" => "ð",
102                          "Zcaron" => "®", "#" => "®", "#381" => "®",                          "Zcaron" => "®", "#381" => "®",
103                          "zcaron" => "¾", "#" => "¾", "#382" => "¾"                          "zcaron" => "¾", "#382" => "¾",
104                  );                  );
105                  $t = intval($str);                  $t = intval($str);
106                  # Skip if not a scalar                  # Skip if not a scalar
107                  if (!is_scalar($str)) return $str;                  if (!is_string($str)) return $str;
108                  # If a number, don't touch it                  # If a number, don't touch it
109                  if (strcmp(intval($str), $str) == 0) return $str;                  if (strcmp(intval($str), $str) == 0) return $str;
110                  # Replace "<BR>" with "\n"                  # Replace "<BR>" with "\n"
# Line 58  Line 115 
115                  $str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str);                  $str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str);
116                  # Remove "<HEAD>"/"</HEAD>", and anything in between.                  # Remove "<HEAD>"/"</HEAD>", and anything in between.
117                  $str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str);                  $str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str);
118                  # Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>" and "<P>" tags                  # Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>",
119                  $str = preg_replace("/(\<\s*(HTML|HEAD|BODY|FONT|P)[^\>]*\>|\<\/\s*(HTML|HEAD|BODY|FONT|P)\s*\>)/im", '', $str);                  # "<P>" and "<BR>" tags, along with their pairs
120                    $str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str);
121                    # 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                  # Replace "\n<LI>" or "<LI>\n" with "<LI>"                  # 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);                  $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                  # 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);                  $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                  # 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);                  $str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str);
130                  # Replace "``" and "''" with """ (a single double quote)                  # Replace "``" and "''" with """ (normal ASCII double quote)
131                  $str = str_replace("“", '"', $str);                  $str = str_replace("“", '"', $str);
132                  $str = str_replace("”", '"', $str);                  $str = str_replace("”", '"', $str);
133                  # Replace "-" with "-"                  # Replace "-" with "-"

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.26