5 function htmlparse($data)
8 if function finds anything unsafe,it will return
9 FALSE and saves a reason info global variable $htmlparse
14 $data = StrToLower(" ".$data);
16 // tags, I don
\14 need to close
17 $unpaired = Array('br'=>1,
18 'br/'=>1, // fix later ;)
26 $allowed = Array('b'=>1,
51 'br/'=>1, // fix later
75 this part will go trought string and will ensure, if all tags are closed
78 $tok = StrTok($data, '<');
80 while(!($tok === FALSE)){
81 if(!StrStr($tok,'>')):
82 $htmlparse = 'Chyba HTML syntaxe!';
83 //$htmlparse = 'Wrong HTML syntax!';
85 elseif(StrStr($tok,"<")):
86 $htmlparse = 'Chyba HTML syntaxe!';
87 //$htmlparse = 'Wrong HTML syntax!';
94 main part of the function - it will check allowed tags, some parameters and so on...
97 $tok = StrTok($data, '<');
100 while(!($tok === FALSE)):
102 $tag = Split('>',$tok,2);
103 $attrib = Split("[[:space:]>]",$tag[0],2);
104 if($allowed[$attrib[0]] != 1 && $allowed[SubStr($attrib[0],1)] != 1): // if tag isn
\14 in allowed array
105 $htmlparse = 'Zakazany tag <'.$attrib[0].'>!';
106 //$htmlparse = 'Forbidden tag <'.$attrib[0].'>!';
109 if('/'.$tags[$j] == $attrib[0]): // closing tag for last opening tag
110 if($tags[$j] == 'table' && $opened_tables > 0):
114 elseif($tags[$j] == 'xmp'): // XMP tag...ignore eny other tags between them
116 if(SubStr($attrib[0],0,1) == '/' && $unpaired[$tags[$j]]): // do I need to close the tag?
119 elseif(SubStr($attrib[0],0,1) == '/'): // am I closing something, I didn
\14 open?
120 $htmlparse = 'Chyba u tagu <'.$tag[0].'>! Zavirate tag, ktery jste neotevrel!';
121 //$htmlparse = 'Error near tag <'.$tag[0].'>! Closing tag, that wasn
\14 opened!';
123 elseif(Ereg(' on',' '.$attrib[1])): // temporary solution for pernament problem...and it isn
\14 suicide
124 $htmlparse = 'JavaScript je na hovno!';
125 //$htmlparse = 'JavaScript sux!';
127 elseif(Ereg(' style',' '.$attrib[1])): // styles are forbidden - don
\14 look at me THAT way ;)
128 $htmlparse = 'Ten "style" se mi tam nezda!';
129 //$htmlparse = '"styles" are forbidden!';
131 elseif(Ereg('://',' '.$attrib[1]) && $attrib[0] != "img" && $attrib[0] != "a"): // adresses in attributes (except A and IMG tags) are forbidden
132 $htmlparse = 'Neco se mi tam nelibi! To je hlaska HTML validace - nejedna se o nejakou cenzuru ;)';
133 //$htmlparse = 'Forbidden usage of adresses in tags!';
135 elseif((SubStr_Count($attrib[1],'"')%2) > 0): // are quotes closed? can do mess if they aren
\14
136 $htmlparse = 'Neuzavrel jste uvozovky uvnitr tagu <'.$attrib[0].'>!';
137 //$htmlparse = 'Close quotes in tag <'.$tag[0].'>!';
139 elseif(Ereg('\?',$attrib[1]) && $attrib[0] == 'img'): // don
\14 allow parameters in IMG tags
140 $htmlparse = 'Chyba u tagu <img> - nejsou povoleny parametry v adrese!';
141 //$htmlparse = 'Error in tag <img> - parameters in image adresses are forbidden!';
143 elseif(($attrib[0] == 'td' || $attrib[0] == 'tr') && $opened_tables == 0):
144 $htmlparse = 'Strkej si ty tagy do vlastni tabulky, jo?';
146 elseif($attrib[0] == 'table'):
150 $tags[$j] = $attrib[0];
158 just check, if all tags are properly closed
162 if($unpaired[$tags[$j]]):
166 $htmlparse = 'Neuzavrel jste tag <'.$tags[$j].'>!';
167 //$htmlparse = 'Tag <'.$tags[$j].'> wasn
\14 closed correctly!';