/[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.5 by ravilov, Thu Aug 16 09:08:42 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), "¹ðèæ¾", "©ÐÈÆ®");
                 $str = preg_replace("/(\<\/?\s*(\w+)>[^\>]*\>)/e",  
                         "array_search(strtoupper('\\2'),\$allowed,false)?'\\1':HTMLSpecialChars('\\1')",  
                         $str);  
                 $str = preg_replace("/(^\s+|\s+$)/", "", $str);  
                 $str = ereg_replace("\"", "&quot;", $str);  
                 return $str;  
4          }          }
5          function ParseNewline($str) {  
6                  if (!$str) return $str;          function MyLower($str) {
7                  $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', '</p> <p class="ptext">', $str);                  return strtr(strtolower($str), "©ÐÈÆ®", "¹ðèæ¾");
8                  $str = preg_replace('/\s*(\r\n|\n\r|\r|\n)/m', '<br>', $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          function MyQuote($str) {  
48                  global $dbh;          function MyEscape($str, $full = true) {
49                  if (!$dbh) return "'$str'";                  $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD");
50                  return $dbh->quote($str);                  $str = preg_replace("/(^\\s+|\\s+$)/", "", $str);
51          }                  $str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'.
52          function MyMove($src, $dest) {                          '\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str);
53                  $cmd = "mv -f '".EscapeShellCmd($src)."' '".EscapeShellCmd($dest)."'";                  $str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str);
54                  return exec($cmd);                  $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;
74          }          }
75          function MyDelete($src) {  
76                  @unlink($src);          function ParseNewline($str, $paragraphs = false) {
77                    if (!$str) return $str;
78                    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                    return nl2br($str);
80          }          }
81    
82          function error($msg) {          function error($msg) {
83                  if (is_array($msg)) $msg = implode(" ", $msg);                  if (is_array($msg)) $msg = implode(" ", $msg);
84                  echo "<BR>\n<FONT COLOR=\"#FF0000\">[".HTMLSpecialChars($msg).                  echo "<BR>\n<FONT COLOR=\"#FF0000\">[".HTMLSpecialChars($msg)."]</FONT><BR>\n";
                         "]</FONT><BR>\n";  
         }  
         function PicSize($pic) {  
                 global $syspicdir;  
                 $ret = array(0, 0);  
                 if ($pic) {  
                         @$size = GetImageSize($syspicdir."/".$pic);  
                         $ret = array($size[0], $size[1]);  
                 }  
                 return $ret;  
85          }          }
86          function isEdit() {  
87                  global $PHP_SELF;          function convert_html($str) {
88                  return stristr($PHP_SELF, "/edit/") ? true : false;                  $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                            "Ccaron" => "È", "#268" => "È", "#268" => "È",
97                            "ccaron" => "è", "#232" => "è", "#269" => "è",
98                            "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
99                            "cgrave" => "æ", "#230" => "æ", "#263" => "æ",
100                            "???" => "Ð", "#272" => "Ð", "#" => "Ð",
101                            "???" => "ð", "#273" => "ð",
102                            "Zcaron" => "®", "#381" => "®",
103                            "zcaron" => "¾", "#382" => "¾",
104                    );
105                    $t = intval($str);
106                    # Skip if not a scalar
107                    if (!is_string($str)) return $str;
108                    # 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                    # Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>",
119                    # "<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>"
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                    # Replace "``" and "''" with """ (normal ASCII double quote)
131                    $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          }          }
143  ?>  ?>

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

  ViewVC Help
Powered by ViewVC 1.1.26