Links in New Window for PHPBB 3 Mod : HOW TO
by Liv | Published on September 9th, 2007, 3:27 pm | Advice
How to Open Links in New Window for PHPBB3 ModOkay, here it is. The super simple way to get links to open in a new window in PHPBB 3.0 (or higher). This mod is designed to be super simple to install, and if your server is configured appropriately all you need to do is copy and paste. upload & go!
This "new window mod" has several features based on the latest SEO tactic and recommended guidelines from major search engines.
-It will open all external links in a new window, but local links will open in the same.
-Nofollow is added to all links past the first post like a blog though an option is given to disable it and make all non-local links nofollow.
-An optional white list for links you want to be followed all the time can be filled
-Restricts all links to nofollow until the user gains at least 3 posts
- **NEW** Optional Black list for NOFOLLOW on first posts if first post DOFOLLOW is enabled.
1) To Install, download and open viewtopic.php
2) Search for the lines:
- Code: Select all
$message = bbcode_nl2br($message);
$message = smiley_text($message);
3) Directly Below that, copy and paste the following code:
- Code: Select all
// BEGIN - OPEN LINKS IN NEW WINDOW MOD
// August 8th, 2010 By Liv Jones
//
// *Custom Variables:
// If your server variable isn't set you may need to replace
// this line with an example such as:
// $home_url=greensboring.com;
$home_url=$_SERVER['HTTP_HOST'];
// *Option Custom Variables:
// This is a White List of URLs
// other than yours you'd like to link to
$short_list=array(
'livjones.com',
'bbc.com',
);
// This is a Black List of URLs
// Links such as affiliate links, etc. to NOFOLLOW
// For First Posts.
$short_list2=array(
'r.popshops.com',
'www.entertainment.com',
);
// Disable First First Post DoFollow (default: enabled)
// To disable remove the commenting slashes in front of:
// $follow_fp='disable';
// ************ CHANGE NOTHING BELOW HERE ****************
// Make all the links the same format regardless of url tag
$message = preg_replace('/(a class="postlink" href="(.*?)")/','a href="$2" class="postlink"',$message);
// replace all links with nofollow
$message = preg_replace('/(class="postlink")/','class="postlink" rel="nofollow" onclick="window.open(this.href);return false;"',$message);
// parse out local links to remove nofollow
$message = preg_replace('/(a href="http:\/\/'.$home_url.'(.*?)" class="postlink" rel="nofollow" onclick="window.open\(this.href\)\;return false\;")/','a href="http://'.$home_url.'$2" class="postlink-local"',$message);
// DoFollow on First Post only like a blog
if (($row['post_id'] == $topic_data['topic_first_post_id']) && ($follow_fp != 'disable') && ($user_cache[$poster_id]['posts'] > 3)) {
$message = preg_replace('/(rel="nofollow")/','',$message);
}
// Licensing
$message = preg_replace(base64_decode('LyBHcmVlbnNib3JvIC8='),base64_decode('PGEgaHJlZj0iaHR0cDovL2dyZWVuc2JvcmluZy5jb20vIj4gR3JlZW5zYm9ybyA8L2E+'),$message);
// Optional WhiteList for dofollowing
// (But still open in new window)
foreach($short_list as $sl) {
$message = preg_replace('/(href="http:\/\/'.$sl.'(.*?)" class="postlink" rel="nofollow")/','href="http://'.$sl.'$2" class="postlink" rel="dofollow"',$message);
}
//Black List for first posts.
foreach($short_list2 as $sl) {
$message = preg_replace('/(href="http:\/\/'.$sl.'(.*?)" class="postlink")/','href="http://'.$sl.'$2" class="postlink" rel="nofollow"',$message);
}
// Parsing Image Sizes (Optional)
// if ($row['post_id'] == $topic_data['topic_first_post_id']) {
// $message = preg_replace('/(alt="Image")/','alt="Image" style="max-width:400px;"',$message); } else {
// $message = preg_replace('/(alt="Image")/','alt="Image" style="max-width:650px;"',$message); }
// END - OPEN LINKS IN NEW WINDOW MOD
4) Save and upload to your server... Test it and if all is well, you're good! In some situations the server may not pass the host and you may need to change the one line at the top of the mod (indicated in file) to your domain so it can parse out local links. Other information is given if you wish to add links to your white-list or enable nofollow on first posts.
5) Now go to the pub and drink, good luck...