Hi, first time posting in the forums, and not sure whether this is the right category for it, I will continue anyway.

My problem is that I would like to add prefixes to any URLs in content which leads to other sites.

For example, I would like to do something similar to making a link like this:

http://hazexp.googlepages.com/test.png

Turn into something like this:

http://anonym.to/?http://hazexp.googlepages.com/test.png

One other thing is that I would like it if it were possible to make this exclude any URLs that are linking to the Drupal setup, i.e. not to convert http://www.example.com/drupal/* links into http://anonym.to/?http://www.example.com/drupal/*

If anyone could be of assistance, it would be *greatly* appreciated.

Comments

artem_sokolov’s picture

Try digging the code of bbcode module, it converts urls into links, so you can change its behaviour to prefix every url it sees.

hazexp’s picture

I previously had the BBCode input format installed, only problem is I don't have any knowledge of PHP, and can't really edit the module, as I have no idea where to start. I have edited a couple of other modules, but the code in this wasn't as readable as to what the BBCode PHP was actually doing (while still reasonably documented).

EDIT: Eventually realised I was reading through the wrong file (the MODULE instead of the INC). Was easy from there, thanks heaps for that, much appreciated.

cs8c’s picture

This is how it needs to look in the bbcode-filter.inc file in these two different spots at starting line 161:

    // Links without a protocol, with a protocol, and with good looking text
    '#\[url(?::\w+)?\]www\.([\w:;&,%+~!=@\/\.\-\#\?]+?)\[/url(?::\w+)?\]#si' => '<a href="http://anonym.to/?http://www.\\1" class="bb-url">\\1</a>',
    '#\[url(?::\w+)?\]([\w:;&,%+~!=@\/\.\-\#\?]+?)\[/url(?::\w+)?\]#si'   => '<a href="http://anonym.to/?\\1" class="bb-url">\\1</a>',
    '#\[url=www\.([\w:;&,%+~!=@\/\.\-\#\?]+?)\](.*?)\[/url(?::\w+)?\]#si' => '<a href="http://anonym.to/?http://www.\\1" class="bb-url">\\2</a>',
    '#\[url=([\w:;&,%+~!=@\/\.\-\#\?]+?)\](.*?)\[/url(?::\w+)?\]#si'      => '<a href="http://anonym.to/?\\1" class="bb-url">\\2</a>',

and line 242:

    // matches an "xxx://yyyy" URL at the start of a line, or after a space.
    // xxxx can only be alpha characters.
    // yyyy is anything up to the first space, newline, comma, double quote or <
    $ret = preg_replace('#(?<=^|[\t\r\n >\(\[\]\|])([a-z]+?://[\w\-]+\.([\w\-]+\.)*\w+(:[0-9]+)?(/[^ "\'\(\n\r\t<\)\[\]\|]*)?)((?<![,\.])|(?!\s))#i', '<a href="http://anonym.to/?\1">\1</a>', $ret);

    // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
    // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
    // zzzz is optional.. will contain everything up to the first space, newline,
    // comma, double quote or <.
     $ret = preg_replace('#([\t\r\n >\(\[\|])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\'\(\n\r\t<\)\[\]\|]*)?)#i', '\1<a href="http://anonym.to/?http://\2.\3">\2.\3</a>', $ret);