MyBB Community Forums

Full Version: [url] Redirection url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I've made a small modification for my own forum and I thought it would be nice to share it. It's meant for passing all urls in postings (excluding email urls) to an external script.
The intention is to effectively disable passing the thread page as referral URL to the external site for privacy or other reasons. Of course a referrer is still passed but it will be the general url of the redirect script, not the exact url of the forum page the link was on.
The URL from the post will be added to the end of the redirect URL (i.e. it will be the last parameter).

You can use some public redirect URL or make the script yourself. Just make sure then that you use a meta redirect (html) instead of a 302 Location redirect HTTP-header, because the latter still passes the original referral URL!

Now the details: it's a change in handling the [url]-tag and involves a new setting under General Configuration.

First, the changed code in functions_post.php. Lookup function doshorturl:
function doshorturl($url, $name="")
{
	//************* added the following line
	global $settings;  // 17-12-2005  Eegee  Mod to use Redirection URL setting
	
	$fullurl = $url;
	// attempt to make a bit of sense out of their url if they dont type it properly
	if(strpos($url, "www.") === 0)
	{
		$fullurl = "http://".$fullurl;
	}
	if(strpos($url, "ftp.") === 0)
	{
		$fullurl = "ftp://".$fullurl;
	}
    if(strpos($fullurl, "://") === false)
    {
        $fullurl = "http://".$fullurl;
    }
	if(!$name)
	{
		$name = $url;
	}
	$name = stripslashes($name);
	$url = stripslashes($url);
	$fullurl = stripslashes($fullurl);
	if($name == $url)
	{
		if(strlen($url) > 55)
		{
			$name = substr($url, 0, 40)."...".substr($url, -10);
		}
	}
  
	//************* added the following 5 lines
	// 17-12-2005  Eegee  Mod to use Redirection URL
	if (isset($settings['redirurl']))
	  if (trim($settings['redirurl']) != '')
	    $fullurl = $settings['redirurl'] . rawurlencode($fullurl);
	// EOMod

	$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";
	return $link;
}
Second, you need to enter a new setting in the Admin CP, Board settings, Add new setting with the following properties:

Setting Title : Redirection URL
Description : Enables redirection on all URLs (except email URLs) in posts. URLs will be passed on to the URL you specify here. Leave empty to revert to default (direct linking).
Setting name : redirurl
Setting type : text
Value : (empty or your URL)
Display order : 11
Group : General Configuration (9)

You should make it a plugin. More people will use it if they don't have to edit everything themselves.
You can use decswxaqz' Easy Install plugin for editing the file. (You can install his "Advanced Plugins" plugin for a tutorial on how to make plugins EI compatible.)
Excellent job, Eegee! I have been looking for something like this for a while now. Cheers! Smile
Thanks Smethead and kodaks for your replies. I'll take a look at Easy Install and Advanced Plugins. I'm only starting with MyBB so I'm still finding out how it all works.
I took a quick look at hook parse_message but it seems this is triggered after all code has been replaced, so that would mean I'd have to find the <a hrefs all by my self again. So this quick hack was easy, but perhaps Easy Install makes it easier Smile and neater.
BTW, if anyone would like it I can also post a simple redirect php-script.