Request: Open link in new tab/window

Message
Author
User avatar
totalmotorcycle
Administrator
Administrator
Posts: 29679
Joined: Sat Nov 22, 2003 1:00 pm
Real Name: Mike
Sex: Male
Years Riding: 32
My Motorcycle: 2013 Moto Guzzi V7 Stone
Location: Winnipeg, Manitoba

Request: Open link in new tab/window

#1 Unread post by totalmotorcycle »

Request: Open link in new tab/window

Dr_Bar requested to see if I could have the links in our forum open up in a new tab or window. I immediately looked into this and found I could modify the phpBB forum code below. While this would only work for NEW (not existing links, unless the message was edited) it's not the ideal solution, but I thought I would give it go.

Unfortunately, thanks to phpBB3.0.x being XHTML compliant and with our phpBB being modified in ways, the code didn't return the results I expected (see below) and immediately reverted to the pervious files... I will have to take a look into other ways it seems. :(

Capture2.jpg
Capture2.jpg (92.75 KiB) Viewed 9024 times

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 105
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 87
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 69
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 105
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 87
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 69
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 105
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 87
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 69
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 105
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 87
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 69
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 105
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 87
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 826: preg_match(): Compilation failed: character value in /x{} or /o{} is too large at offset 69
Modifying auto-detected links

First of all, make auto-detected links (those that you didn't wrap with the url-BBCode) open new windows when getting clicked. Therefor open the includes/functions_content.php and look for following line (which should be around line 592):



Code: Select all

$html = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";



And replace it with following line:



Code: Select all

if ($type == MAGIC_URL_EMAIL)
{
$html = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";
}
else
{
$html = "$whitespace<!-- $tag --><a$class href=\"$url\" onclick=\"window.open(this.href);return false;\">$text</a><!-- $tag -->$append";
}


BBCode URLs

Next open the bbcode.html of your style (if you're using prosilver, this would be the styles/prosilver/template/bbcode.html file) and look for following line:



Code: Select all

<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->



Now replace it with this line:



Code: Select all

<!-- BEGIN url --><a href="{URL}" onclick="window.open(this.href);return false;" class="postlink">{DESCRIPTION}</a><!-- END url -->



Help phpBB read the output again

Last but not least, you should also do the following change which will allow the created HTML output to be parsed again by phpBB: Open the includes/functions.php and replace this segment which you should find around line 2740...



Code: Select all

case 'bbcode_htm':
return array(
'#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
'#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?">.*?</a><!\-\- l \-\->#',
'#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)">.*?</a><!\-\- \1 \-\->#',
'#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
'#<!\-\- .*? \-\->#s',
'#<.*?>#s',
);


... with this one:



Code: Select all

case 'bbcode_htm':
return array(
'#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
'#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- l \-\->#',
'#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- \1 \-\->#',
'#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
'#<!\-\- .*? \-\->#s',
'#<.*?>#s',
);


And since you've updated also a template file, don't forget to also purge your board's cache through the respective button on the frontpage of your board's admin panel.

Note: The change will not affect existing posts, you must edit them so they can be reprocessed.
NEW 2024 Motorcycle Model Guides
2023 Motorcycle Model Guides

Total Motorcycle is official Media/Press for Aprilia, Benelli, Beta, Bimota, BMW, Brammo, Buell, Can-Am, CCW, Ducati, EBR, Harley-Davidson, Honda, Husqvarna, Husaberg, Hyosung, Indian, Kawasaki, KTM, KYMCO, LiveWire, Moto Guzzi, Moto Morini, MV Agusta, Norton, Phantom, Piaggio, Polaris, Ridley, Roehr, Royal Enfield, Suzuki, Triumph, Ural, Vespa, Victory, Yamaha and Zero.

Post Reply