MyBB Community Forums

Full Version: Block URLs you don't like
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In addition to my tutorial Adding nofollow to outgoing links here is another MyCode hack. Wink

This MyCode will remove all URLs in posts/signatures/pm you don't like.

Title
URL Blacklist

Regular Expression
<a href="http([s]?)://(www\.example\.com|example\.com|www\.google\.com)(.*?)" (.*?)>(.*?)</a>

Replacement
<span style="font-style: italic; color: rgb(255, 0, 0)">URL removed</span>

This is just an example and will block:

www.example.com
example.com
www.google.com

To modify the blacklist edit this:
www\.example\.com|example\.com|www\.google\.com

The pipe stays for an OR and you have to add a backslash before every dot.

If you just want to remove the 'clickable effect' use this replacement:
http$1://$2$3
Another wonderful contribution of you, just as usual.
(2011-01-18, 03:36 PM)querschlaeger Wrote: [ -> ]Regular Expression
<a href="http([s]?)://(www\.example\.com|example\.com|www\.google\.com)(.*?)" (.*?)>(.*?)</a>

You could probably shorten it a bit.

https?://(www\.|)(example\.com|google\.com)

If you want to be zealous maybe even ignore the tld at the end, if you actually want to block google.com you have a problem because there's also google.net google.de google.co.uk google.co.jp google.younameit...
(2011-01-20, 12:00 PM)frostschutz Wrote: [ -> ]
(2011-01-18, 03:36 PM)querschlaeger Wrote: [ -> ]Regular Expression
<a href="http([s]?)://(www\.example\.com|example\.com|www\.google\.com)(.*?)" (.*?)>(.*?)</a>

You could probably shorten it a bit.

https?://(www\.|)(example\.com|google\.com)

If you want to be zealous maybe even ignore the tld at the end, if you actually want to block google.com you have a problem because there's also google.net google.de google.co.uk google.co.jp google.younameit...

If you use this regex it's not possible to just remove the 'clickable effect'. I made this MyCode primarily to remove the <a href... from a link but still show the URL as regular text.

Also you have to add the HTML code <a href... when using the MyCode editor as a filter because it's running after internal URL MyCodes of MyBB (so URLs are already parsed).
Great idea! I might use this to block a spammer that comes to my site. Thanks!
I'd cheat by adding (.?*) before the entire URL submatch to match both www and non-www URLs. Also, the 4th submatch should be placed straight after the preceding one:

(<a href="http([s]?)://(www\.)?(google\.com)[^>]*>(.*?)</a>)|(http([s]?)://(www\.)?(google\.com)[^"\s]*)

This will block Google for all the countries, but you should be able to easily adapt it to your needs.