Home

Your premium source for custom modification services for phpBB

  logo

HomeForumsBlogMOD ManagerFAQSearch Log in

The phpBB Doctor is currently available for private clients only. At this time we are not accepting any new work until we can clear out our current backlog. Thank you for your patience.

 

[Final] Internal (Site) Links Open in Same Window


 
Register or Login to Post    ForumsMOD Catalog
View previous topic :: View next topic  
Author Message
phpbbDoctor
Site Admin


Joined: 12 Apr 2005

Posts: 269

None Selected

Post Subject: [Final] Internal (Site) Links Open in Same Window
Sat Apr 30, 2005 9:27 am

There's nothing more annoying to us than having someone link from one post to another in a phpBB forum, clicking that link, and having to deal with a new browser windows. Shocked It just doesn't make sense, does it? Afterall, it is staying on the same site... even staying on the same board! If we wanted a new window, there are ways to do that (right-click menu, shift-click on the link, and so on).

So we fixed that. Smile Here are some examples of various types:

Local link:
http://www.phpbbdoctor.com/viewtopic.php?t=8

Another local link, no http this time:
www.phpbbdoctor.com/viewtopic.php?t=8

Local link via BBCode
http://www.phpbbdoctor.com/viewtopic.php?t=8

Local link with masked URL
About the phpBB Doctor

Remote Link:
www.momentsoflight.com

Remote link formatted with BBCode
http://www.momentsoflight.com

Remote link with masked URL
Awesome Photography

You'll notice that all of the "local" links (located here on the phpBB Doctor site) will open in the same window that you are currently using, while the "remote" links open in a new window. How?

Here you go. Cool

open includes/bbcode.php
find
Code:
$bbcode_tpl = null;

after, add
Code:
// BEGIN Local URLs (www.phpBBDoctor.com)
// This function is used to parse urls after the first pass processing.
// If the URL is "local" (as defined by having a link to a domain on
// the same server as that hosting this phpBB board) then the code that
// opens a new window (target="_blank") is removed. That way when someone
// links internally on your board it will preserve the session, and will
// NOT open a new window. I hate that. :-)  (www.phpBBDoctor.com)
function local_urls($text)
{
        global $board_config;

        // First build the match for local URL links. If you are running
        // multiple boards on the same server, and want different boards
        // to open in new windows even though they are on the same host
        // hardware, then use the optional line designated below instead.

        // Note: strtolower() is only used for comparison, the actual text
        // of the URL is not changed.
        $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
        $server_port = (( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) : '') . '/';
        $server_name = strtolower($board_config['server_name']);
        $script_path = strtolower($board_config['script_path']);

        $local_url = '<a href="' . $server_protocol . $server_name . $server_port;
        // OPTIONAL
        // Use this line if you want to include the script path as well.
        // To use this line simply remove the two / from the beginning.
        //$local_url = '<a href="' . $server_protocol . $server_name . $server_port . $script_path;

        // Now look to see if that string is found in the text. Note that
        // the first step done (in other functions) before processing the
        // post text is to add one extra space, so we don't need to worry
        // about the case where a URL might be in the very first position.
        // It won't. :-)
        $start_url = strpos(strtolower($text), $local_url);

        while ($start_url)
        {
                // First identify the end of the URL by finding the >
                $last_found_pos = $start_url + 1;
                $end_url = strpos ($text, '>', $last_found_pos);
                $url_len = $end_url - $start_url + 1;

                // Next get a copy of the URL from <a href="... to closing >
                $my_url = substr($text, $start_url, $url_len);

                // replace target wtih null string
                $my_local_url = str_replace('target="_blank"', '', $my_url);

                // Replace old URL with new URL in post text. Note that while
                // the comparison was done in lower case via the strtolower()
                // function, the actual URL text is not changed in any way.
                // Only the target.
                $text = str_replace($my_url, $my_local_url, $text);

                // Advance by length of URL minus length of "target" string
                // and check for another local URL in the same post text.
                $start_url = strpos(strtolower($text), $local_url, $last_found_pos + $url_len - 16);
        }

        return $text;
}
// END Local URLs (www.phpBBDoctor.com)


Find
Code:
        // Remove our padding from the string..
        $text = substr($text, 1);

        return $text;

} // bbencode_second_pass()


Before, Add
Code:
        // BEGIN Local URLs (www.phpBBDoctor.com)
        $text = local_urls($text);
        // END Local URLs (www.phpBBDoctor.com)


find
Code:
        // Remove our padding..
        $ret = substr($ret, 1);

        return($ret);
}

Before, Add
Code:
        // BEGIN Local URLs (www.phpBBDoctor.com)
        $ret = local_urls ($ret);
        // END Local URLs (www.phpBBDoctor.com)

This MOD has been installed at the phpBBDoctor.com
Back to top
Display posts from previous:   
Register or Login to Post    ForumsMOD Catalog
Page 1 of 1 All times are GMT - 5 Hours

 
Jump to:  

HomeForumsMOD ManagerFAQSearch Register Log in
Not endorsed by or affiliated with the phpBB Group
Powered by phpBB © phpBB Group
Terms of Service
Web design by MomentsOfLight.com logo