/[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.4 by ravilov, Mon Aug 13 08:16:02 2001 UTC revision 1.12 by ravilov, Wed Sep 19 14:16:34 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("\<", "&lt;", $str);  
                 $str = ereg_replace("\>", "&gt;", $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 my_replace($str, $start, $end, $pat = "", $rep = "") {
27                    if (!$pat) $pat = '\s*(\r\n?|\n\r?)';
28                    $idx1 = $idx2 = -1;
29                    while (true) {
30                            $str2 = strtoupper($str);
31                            $idx1 = strpos($str2, $start, $idx1 + 1);
32                            if ($idx1 === false) break;
33                            $idx2 = strpos($str2, $end, $idx2 + 1);
34                            if ($idx2 === false) break;
35                            if ($idx1 > $idx2) break;
36                            $idx2 += strlen($end);
37                            $str1 = substr($str, 0, $idx1);
38                            $str2 = preg_replace('/'.$pat.'/m', $rep,
39                                    substr($str, $idx1, $idx2 - $idx1));
40                            $str3 = substr($str, $idx2, strlen($str) - $idx2);
41                            $str = $str1.$str2.$str3;
42                    }
43                  return $str;                  return $str;
44          }          }
45          function MyQuote($str) {  
46                  global $dbh;          function MyEscape($str, $full = true) {
47                  if (!$dbh) return "'$str'";                  $allowed = array("", "A", "B", "I", "U", "UL", "OL", "LI", "TABLE", "TR", "TH", "TD");
48                  return $dbh->quote($str);                  $str = preg_replace("/(^\\s+|\\s+$)/", "", $str);
49          }                  $str = preg_replace('/(\<\/?\s*(\w+)\\b[^\>]*\>)/e', 'array_search(MyUpper("\2"),'.
50          function MyMove($src, $dest) {                          '\$allowed,false)?"\1":HTMLSpecialChars("\1")', $str);
51                  $cmd = "mv -f '".EscapeShellCmd($src)."' '".EscapeShellCmd($dest)."'";                  $str = preg_replace('/(\<\s*A\b)/i', '\\1 target=_blank class=more', $str);
52                  return exec($cmd);                  $str = preg_replace('/(\<\s*TABLE\b)/i', '\\1 class=normal', $str);
53                    $str = my_replace($str, "<TABLE", "/TABLE>");
54                    $str = my_replace($str, "<UL", "/UL>", true);
55                    $str = my_replace($str, "<OL", "/OL>");
56                    if (!$full) my_replace($str, "<", ">", '"', "'|'");
57                    $str = str_replace('"', "&quot;", $str);
58                    if (!$full) $str = str_replace("'|'", '"', $str);
59                    return $str;
60          }          }
61          function MyDelete($src) {  
62                  @unlink($src);          function ParseNewline($str, $paragraphs = false) {
63                    if (!$str) return $str;
64                    if ($paragraphs) $str = preg_replace('/\s*(\r\n\r\n|\n\r\n\r|\n\n|\r\r)/m', ' </p><p class="ptext">', $str);
65                    return nl2br($str);
66          }          }
67    
68          function error($msg) {          function error($msg) {
69                  if (is_array($msg)) $msg = implode(" ", $msg);                  if (is_array($msg)) $msg = implode(" ", $msg);
70                  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;  
71          }          }
72          function isEdit() {  
73                  global $PHP_SELF;          function convert_html($str) {
74                  return stristr($PHP_SELF, "/edit/") ? true : false;                  $entities = array(
75                            "nbsp" => " ", "#160" => " ",   # nbsp
76                            "amp" => " ", "#38" => " ",     # amp
77                            "quot" => "\"", "#34" => "\"",  # quot
78                            "lt" => "<", "#60" => "<",      # lt
79                            "gt" => ">", "#62" => ">",      # gt
80                            "Scaron" => "©", "#352" => "©",
81                            "scaron" => "¹", "#353" => "¹",
82                            "Ccaron" => "È", "#268" => "È", "#268" => "È",
83                            "ccaron" => "è", "#232" => "è", "#269" => "è",
84                            "Cgrave" => "Æ", "#262" => "Æ", "#" => "Æ",
85                            "cgrave" => "æ", "#230" => "æ", "#263" => "æ",
86                            "???" => "Ð", "#272" => "Ð", "#" => "Ð",
87                            "???" => "ð", "#273" => "ð",
88                            "Zcaron" => "®", "#381" => "®",
89                            "zcaron" => "¾", "#382" => "¾",
90                    );
91                    $t = intval($str);
92                    # Skip if not a scalar
93                    if (!is_string($str)) return $str;
94                    # If a number, don't touch it
95                    if (strcmp(intval($str), $str) == 0) return $str;
96                    # Replace "<BR>" with "\n"
97                    $str = preg_replace("/\<BR\>/m", "\n", $str);
98                    # Replace "<...>\n" with "<...>"
99                    $str = preg_replace("/(\<[^\/][^\>]*\>)\s*(\r\n?|\n\r?)\s*/m", '$1', $str);
100                    # Replace "\n</...>" with "</...>\n"
101                    $str = preg_replace("/\s*(\r\n?|\n\r?)\s*(\<\/[^\>]+\>)/m", '$2$1', $str);
102                    # Remove "<HEAD>"/"</HEAD>", and anything in between.
103                    $str = preg_replace("/\<\s*HEAD[^\>]*\>.*\<\/\s*HEAD\s*\>(\r\n?|\n\r?)*/ims", '', $str);
104                    # Remove all "<HTML>", "<HEAD>", "<BODY>", "<FONT>", "<TABLE>", "<TR>", "<TH>", "<TD>",
105                    # "<P>" and "<BR>" tags, along with their pairs
106                    $str = preg_replace("/\<\/?\s*(HTML|HEAD|BODY|FONT|P|BR)[^\>]*\>/im", '', $str);
107                    # Remove all table elements "<TABLE>", "<TR>", "<TH>", "<TD>")
108                    #$str = preg_replace("/\<\/?\s*(TABLE|TR|TH|TD)[^\>]*\>/im", '', $str);
109                    # "<P>" and "<BR>" tags, along with their pairs
110                    # Replace "\n<LI>" or "<LI>\n" with "<LI>"
111                    $str = preg_replace("/(\s*(\r\n?|\n\r?))*(\<\/\s*LI\s*\>)(\s*(\r\n?|\n\r?))*/m", '$3', $str);
112                    # Replace "<UL>\n" or "<OL>\n" with "<UL>" or "<OL>", respectively
113                    $str = preg_replace("/(\<\s*(UL|OL)\s*\>)(\s*(\r\n?|\n\r?))+/m", '$1', $str);
114                    # Replace "\n</UL>" or "\n</OL>" with "</UL>" or "</OL>", respectively
115                    $str = preg_replace("/(\s*(\r\n?|\n\r?))+(\<\/\s*(UL|OL)\s*\>)/m", '$3', $str);
116                    # Replace "``" and "''" with """ (normal ASCII double quote)
117                    $str = str_replace("“", '"', $str);
118                    $str = str_replace("”", '"', $str);
119                    # Replace "-" with "-"
120                    $str = str_replace("—", '-', $str);
121                    # Replace character references ("&...;" and "&#...;") with its value
122                    $str = preg_replace("/\&([^;]+);/em", '$entities["$1"]?$entities["$1"]:"?"', $str);
123                    # Remove all whitespace at beginning or ending of a line
124                    $str = preg_replace("/(^\s+|\s+$)/", '', $str);
125                    # Convert Win1250 to ISO8859-2
126                    $str = strtr($str, "ŠÐÈÆŽšðèæž", "©ÐÈÆ®¹ðèæ¾");
127                    return $str;
128          }          }
129  ?>  ?>

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.26