ID:153248
 
What do u think is the best way to block HTML from Say() and World Chat(). i tried blocking phrases such as <font size and <font but ive found that i could get by that but doing <font___size(adding spaces not and underscore). Any help is appreciated.
I just block < and >

since those are the core symbols used for html
In response to Jon Snow
but what if sum1 wanted to tell sum1 how to make a certain HTML tag. they couldnt use <>. or if they wanted to use it for sumthin else
In response to Mike H
o thanks that just wat i wantd. i was lookign for sumthin liek this in the ref but i guess i missed it =(
In response to FinalFantasyGamer
tell them to do it through pager
In response to Mike H
Mike H wrote:
html_encode()

or ProcessHTML() if you want to allow some tags (or just certain arguments of some tags) and disable others. :)
In response to Mike H
While html_encode() is nice, and all, I think it should really be two procs. It seems to me to preform a dual action of changing the < and > characters to &lt; and &gt; but it also modifies other non-transmittable characters, like ' and " and & and others.

I found this to be a big problem in Chatters, as html_encoding would break links, like when you link to a forum post.

It seems like html_encode() was a muddled idea which was only half-implemented in two differeing directions. One was to disable the use of html, the other to mask non-transmittable characters, like '. Oddly enough, it doesn't mask the space character, so it's use in URLifying is null, and it's intereference with normal BYOND features, like autolinks makes it only half as good as it could be.

I use 2 procs I wrote myself in Chatters to handle disabling and stripping html in messages. The first one swaps < for &lt; and > for &gt; like html_encode() does, but it skips over those parts of the mesage that would be auto-linked, preserving the link.

I call this one http_encode(), but the name is not very descriptive, becuase it doesn't encode things to be URL friendly. Anyways, here's that proc:

proc
http_encode(var/text)
var/pos1 = findtext(text,"http://")
if(!pos1) pos1 = findtext(text, "byond://")
if(!pos1) pos1 = findtext(text, "telnet://")
if(!pos1) pos1 = findtext(text, "irc://")
if(pos1)
var/pos2
var/part1
var/link
var/part2
var/text_copy
while(pos1)
pos2 = findtext(text,"<",pos1)
if(!pos2)
pos2 = findtext(text," ",pos1)
if(!pos2)
pos2 = findtext(text,ascii2text(9),pos1) // tab character
if(!pos2)
pos2 = findtext(text, ascii2text(10),pos1) // newline character
if(!pos2) pos2 = length(text)

part1 = html_encode(copytext(text, 1, pos1))
link = copytext(text, pos1, pos2)
part2 = copytext(text, pos2)

pos1 = findtext(part2, "http://")
if(!pos1) pos1 = findtext(part2, "byond://")
if(!pos1) pos1 = findtext(part2, "telnet://")
if(!pos1) pos1 = findtext(part2, "irc://")
text = part2

if(!pos1)
part2 = html_encode(part2)
text_copy += part1 + link + part2
else
text_copy += part1 + link

text = text_copy

else
text = html_encode(text)
return text


My second proc simply removes everything between < and >, including the brackets. Use this when you don't even want the raw html code to show:

proc
strip_html(var/text)
if((!text) || (!length(text)))
return
if(!findtext(text, "<"))
return text
var/pos = findtext(text, "<")
while(pos)
var/pos2 = findtext(text, ">", pos)
if(pos2)
if(findtext(text, "<", pos+1, pos2-1))
pos = findtext(text, "<", pos2)
continue
var/part1 = copytext(text, 1, pos)
var/part2 = copytext(text, pos2 + 1)
text = part1 + part2
pos = findtext(part2, "<")
if(pos)
pos += length(part1)
else pos = findtext(text, "<", pos+1)
return text


Both of these procs work, and have been used heavily in Chatters for quite some time with no errors or bugs. Hope that helps.

~X
In response to Xooxer
My version of strip_html(), developed independently for The Haven Seed on December 2003:

proc/strip_html(string)
var/pos = findtext(string,"<")
var/nextpos = findtext(string,">",pos)
while(pos && nextpos)
string = copytext(string,1,pos) + copytext(string,nextpos+1)
pos = findtext(string,"<")
nextpos = findtext(string,">",pos)
return string
In response to Spuzzum
I never thought of using one loop. :P Very nicely done.

~X