## EasyMod 0.0.7 compliant
############################################################## 
## Mod Title: Local Links
## Mod Version: 1.1.0
## Author: netclectic < adrian@netclectic.com > Adrian Cockburn - http://www.netclectic.com 
## Description: This MOD will cause any local URLs (i.e. www.YOURDOMAIN.com) posted to your 
## board to open in the same window instead of in a new window, ( i.e. _self instead of _blank ). 
## This does not effect external URLs. Might not be to your liking if you do not have your own domain name.
## 
## Installation Level: easy
## Installation Time: 5 Minutes 
## Files To Edit: (2) includes/bbcode.php,
## templates/subSilver/bbcode.tpl
## Included Files: n/a
############################################################## 
## This MOD is released under the GPL License. 
## Intellectual Property is retained by the MOD Author(s) listed above 
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/downloads/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/downloads/ 
############################################################## 
## Author Note: 
##
## Change History:
##        1.1.0 - Confirmed with 2.0.4. Updated to be EasyMod compliant.
##        1.0.3 - Aarrgghhh! Regular expressions!!!.
##        1.0.2 - Fixed small bug in script - .
##        1.0.1 - Fixed some dodgy regular expressions.
##        1.0.0 - Original release.
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 

# 
#-----[ OPEN ]------------------------------------------ 
# 
includes/bbcode.php 

# 
#-----[ FIND ]------------------------------------------ 
# 
$bbcode_tpl['url1'] = str_replace('{URL}', '\1\2', $bbcode_tpl['url']);

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
    // MOD LOCAL URL BEGIN 
	$bbcode_tpl['url_local1'] = str_replace('{URL}', '\\1\\2\\3', $bbcode_tpl['url_local']);
	$bbcode_tpl['url_local1'] = str_replace('{DESCRIPTION}', '\\1\\2\\3', $bbcode_tpl['url_local1']);

	$bbcode_tpl['url_local2'] = str_replace('{URL}', 'http://\\1\\2', $bbcode_tpl['url_local']);
	$bbcode_tpl['url_local2'] = str_replace('{DESCRIPTION}', '\\1\\2', $bbcode_tpl['url_local2']);

	$bbcode_tpl['url_local3'] = str_replace('{URL}', '\\1\\2\\3', $bbcode_tpl['url_local']);
	$bbcode_tpl['url_local3'] = str_replace('{DESCRIPTION}', '\\4', $bbcode_tpl['url_local3']);
	
	$bbcode_tpl['url_local4'] = str_replace('{URL}', 'http://\\1\\2', $bbcode_tpl['url_local']);
	$bbcode_tpl['url_local4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url_local4']);
    // MOD LOCAL URL END 

# 
#-----[ FIND ]------------------------------------------ 
# 
	// [img]image_url_here[/img] code..
	// This one gets first-passed..

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
    // MOD LOCAL URL BEGIN 
    // do any local urls first... 
    // [url]xxxx://www.phpbb.com[/url] code..
  preg_match('/(?:\.)*([a-z0-9\-_]+\.[a-z]+$)/i', $HTTP_SERVER_VARS['SERVER_NAME'], $regs);
  $server_addr = $regs[1];
  
	$local_patterns[1] = "#\[url\]([a-z]+?://){1}(" . $server_addr . ")([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)\[/url\]#si";
	$local_replacements[1] = $bbcode_tpl['url_local1'];                       

	// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
	$local_patterns[2] = "#\[url\](" . $server_addr . ")([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)\[/url\]#si";
	$local_replacements[2] = $bbcode_tpl['url_local2'];

	// [url=xxxx://www.phpbb.com]phpBB[/url] code..
	$local_patterns[3] = "#\[url=([a-z]+?://){1}(" . $server_addr . ")([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)\](.*?)\[/url\]#si";
	$local_replacements[3] = $bbcode_tpl['url_local3'];

	// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
	$local_patterns[4] = "#\[url=(" . $server_addr . ")([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)\](.*?)\[/url\]#si";
	$local_replacements[4] = $bbcode_tpl['url_local4'];
    
    $text = preg_replace($local_patterns, $local_replacements, $text); 
    // now with the local urls done, it's safe to do any external urls 
    // MOD LOCAL URL END 

# 
#-----[ FIND ]------------------------------------------ 
# 
// matches an "xxxx://yyyy" URL at the start of a line, or after a space. 

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
// MOD LOCAL URL BEGIN
// match a local URL and replace with a target="_self" href 
$ret = preg_replace("#([\n ])([a-z]+?)://(" . $server_addr . ")((?:/[^\t <\n\r]*)?)#i", "\\1<a href=\"\\2://\\3\\4\" target=\"_self\">\\2://\\3\\4</a>", $ret); 
$ret = preg_replace("#([\n ])(" . $server_addr . ")((?:/[^\t <\n\r]*)?)#i", "\\1<a href=\"http://\\2\\3\" target=\"_self\">\\2\\3</a>", $ret);
// MOD LOCAL URL END 


# 
#-----[ OPEN ]------------------------------------------ 
# 
templates/subSilver/bbcode.tpl 

# 
#-----[ FIND ]------------------------------------------ 
# 
<!-- BEGIN url --><a href="{URL}" target="_blank" class="postlink">{DESCRIPTION}</a><!-- END url --> 

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
<!-- BEGIN url_local --><a href="{URL}" target="_self" class="postlink">{DESCRIPTION}</a><!-- END url_local -->

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 
