·  News ·  Travel ·  Food ·  Arts ·  Science ·  Sports ·  Advice ·  Religion ·  Life ·  Greensboro · 

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 Mod
Okay, 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...
 
 
Thanks Liv you are the best :D :D
February 1st, 2008, 2:26 pm
amko77
 
If I try internal links and a normal link after it completly removes the new page and nofollow tags. like I have done here.

viewtopic.php?f=23&t=7543

http://www.google.com

Try clicking on the google link. It's now your free link to google. What a bug hey?
Now how do we fix this?
December 1st, 2009, 9:51 am
budinsky
 
I'm not entirely sure why that was occurring but I wanted to make the code standard compliant and use javascript as apart of the code instead of the "_blank" before... I also found a few bugs a long the way but nothing that effected the performance of the code. Why it was doing that, must have been an odd quark in the parsing.... but thanks for bringing it to my attention....

Get the new code (up above) and your links should, (should... I've got major distractions in my house right now) work right!!! :)
December 1st, 2009, 3:52 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Location: Greensboro, NC
Liv wrote:Get the new code (up above) and your links should, (should... I've got major distractions in my house right now) work right!!!)

I tested the code and it seems that the local links get treated as an external link instead. See your local link below
http://greensboring.com/viewforum.php?f=17
I think maybe the following is causing the error:
Code: Select all
(.*?)
December 2nd, 2009, 4:43 am
budinsky
 
Argh!!! Chaos ensues.... Try it now....

I knew I missed something, had to rush and pick up the kids from school.... I've updated the code above & checked it several different ways now, take a look and see what you come up...
December 2nd, 2009, 7:40 pm
User avatar
Liv
I show you something fantastic and you find fault.
 
Location: Greensboro, NC
Why does the word news get autolinked to greensboring.com?
February 4th, 2010, 1:18 pm
Guest
 
Guest wrote:Why does the word news get autolinked to greensboring.com?

Because she has a rewrite rule for news to link to her
February 4th, 2010, 7:44 pm
Guest
 
Feel free to omit that code as long as some sort of attribution link is given.
February 5th, 2010, 10:55 am
User avatar
Liv
I show you something fantastic and you find fault.
 
Location: Greensboro, NC
Hi,
What is a role of whitelist of links? I didn't get any difference...
What about links in signatures? I guess it should be very similar way but in some other file?
Regards,
ape
July 23rd, 2010, 5:14 am
ape
 
ape wrote:Hi,
What is a role of whitelist of links? I didn't get any difference...
What about links in signatures? I guess it should be very similar way but in some other file?
Regards,
ape


Whitelist allows the "nofollow" attribute to be removed in replies.

I block all signatures to search engines... that would be my recommendation to others....
July 23rd, 2010, 10:48 am
User avatar
Liv
I show you something fantastic and you find fault.
 
Location: Greensboro, NC
Thanks Dude It's Work Very well and it's so simple to use
:clap:
August 1st, 2010, 10:33 am
lanclient
 

Return to Advice