Links in new window

How-to's, little tricks, tutorials, code examples (snippets) and read-me's.

Links in new window

Postby Kjell » 02 Oct 2007, 11:04

Getting posted links to open in a new window works with 3.0.4
These changes will make all url's created using the [url] bbcode to open in a new window and any plain text links after the change open in a new window. Any plain text links made before the second change will not open in a new window.

open styles/subsilver2/templates/bbcode.html

Find:
Code: Select all
    <!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->


Replace with:
Code: Select all
    <!-- BEGIN url --><a href="{URL}" class="postlink" target="_blank">{DESCRIPTION}</a><!-- END url -->



Open styles/prosilver/templates/bbcode.html
Find:
Code: Select all
<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->


Replace with:
Code: Select all
<!-- BEGIN url --><a href="{URL}" class="postlink" target="_blank">{DESCRIPTION}</a><!-- END url -->


Open includes/functions_content.php

Find:
Code: Select all
      // matches a xxxx://aaaaa.bbb.cccc. ...
      $magic_url_match[] = '#(^|[\n\t (>.])(' . get_preg_expression('url_inline') . ')#ie';
      $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_FULL, '\$1', '\$2', '', '$class')";



Replace With:
Code: Select all
   // matches a xxxx://aaaaa.bbb.cccc. ...
          $magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('url_inline') . ')#ie';
          $magic_url_replace[] = "'\$1<!-- m --><a target=\"_blank\" href=\"\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&amp;', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&amp;', '&', '\$2'), -10) : '\$2') . '</a><!-- m -->'";


Find:
Code: Select all
      // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
      $magic_url_match[] = '#(^|[\n\t (>])(' . get_preg_expression('www_url_inline') . ')#ie';
      $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_WWW, '\$1', '\$2', '', '$class')";


Replace With:
Code: Select all
    // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
          $magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('www_url_inline') . ')#ie';
          $magic_url_replace[] = "'\$1<!-- w --><a target=\"_blank\" href=\"http://\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&amp;', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&amp;', '&', '\$2'), -10) : '\$2') . '</a><!-- w -->'";
Last edited by Kjell on 14 May 2009, 00:35, edited 9 times in total.
Kjelle
My work - My farm - Ware I live - phpBB support Sweden
"The globe is round, think global", My rules: Be teased is okay on a funny way ;)
User avatar
Kjell    
Supporter
Supporter
 
Posts: 490
Joined: 14 Feb 2007, 13:09
Location: Nordic of Sweden
Favorite Team: NHL N-ville,Forsberg
Gender: Male
phpBB Knowledge: 8


Re: Links in new window

Postby harmlessgoat22 » 02 Oct 2007, 18:11

Thank you, this is a great tutorial! However, I think it would work better in the Tutorials and How-Tos forum.
User avatar
harmlessgoat22    
STG Support Team
STG Support Team
 
Posts: 2886
Joined: 13 Jul 2006, 17:38
Gender: Male
phpBB Knowledge: 8

Re: Links in new window

Postby jdh » 02 Oct 2007, 19:33

Thanks Kjell! :thumbsup: :good: :yahoo: :grin: ;) :D (in a smiley mood..can you tell? :P)
Iron helmets will not save
Even heroes from the grave.
Good men's blood will drain away
while the wicked win the day.
User avatar
jdh    
STG Support Team
STG Support Team
 
Posts: 1508
Joined: 05 May 2007, 08:04
Location: Wisconsin
Gender: Male
phpBB Knowledge: 7

Re: Links in new window

Postby Patricia » 03 Oct 2007, 03:45

Hi,

Is it possible to implement the following Active Link Referrer Blocker mod, which is originaly made for phpbb2 ?

Spoiler:
###############################################
## Hack Title: Active Link Referrer Blocker
## Hack Version: 1.0.0
## Author: Strigoi-Tepes
##
## Description: This hack will block the referrer when a link
## is clicked by going through anonymz.com first.
## When ever a link is posted on the BB, it will
## automatically add the anonymz.com address to the
## link. The whole process is invisible since it is
## added to the main phpbb link processing functions.
## When you edit your post, the link will appear the
## same way as you posted it.
##
## Compatibility: Tested on 2.0.22
##
## Installation Level: Easy
## Installation Time: ~1 minute
##
## Files To Edit: 1
## includes/bbcode.php
##
## Included Files: 0
##
## Author Notes: this hack was
## created back in 2002 then again in 2004.
## This version will work with 2.0.22 and earlier. I
## would like to give credit to the original author of the
## first script "Safeurl Hack" by reimer & "Active link referrer block" by wd2004. I would also like
## to give credit to anonymz.com for providing this great url protection service.
## i have simply hacked the hack to use a new url, i use it on several boards with heavily modded
## bbcode.php and have yet to have an issue.
##
##
##
##
## Support: http://www.phpbbhacks.com/forums
##
###############################################
## You downloaded this hack from phpBBHacks.com, the #1 source for phpBB related downloads.
## Please visit http://www.phpbbhacks.com/forums for support.
###############################################
##
###############################################
## This hack is released under the GPL License.
## This hack can be freely used, but not distributed, without permission.
## Intellectual Property is retained by the hack author(s) listed above.
###############################################

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

#
#-----[ FIND ]------------------------------------------
#

// We do URLs in several different ways..
$bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);

$bbcode_tpl['url2'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);

$bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);

$bbcode_tpl['url4'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);

#
#-----[ REPLACE ]------------------------------------------
#

// We do URLs in several different ways..
$bbcode_tpl['url1'] = str_replace('{URL}', 'http://www.anonymz.com/?\\1', $bbcode_tpl['url']);
$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);

$bbcode_tpl['url2'] = str_replace('{URL}', 'http://www.anonymz.com/?\\1', $bbcode_tpl['url']);
$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);

$bbcode_tpl['url3'] = str_replace('{URL}', 'http://www.anonymz.com/?\\1', $bbcode_tpl['url']);
$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);

$bbcode_tpl['url4'] = str_replace('{URL}', 'http://www.anonymz.com/?\\1', $bbcode_tpl['url']);
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);

#
#-----[ FIND ]------------------------------------------
#

// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
$ret = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// zzzz is optional.. will contain everything up to the first space, newline,
// comma, double quote or <.
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

#
#-----[ REPLACE ]------------------------------------------
#

// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
$ret = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"http://www.anonymz.com/?\\2\" target=\"_blank\">\\2</a>", $ret);

// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// zzzz is optional.. will contain everything up to the first space, newline,
// comma, double quote or <.
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"http://www.anonymz.com/?\\2\" target=\"_blank\">\\2</a>", $ret);

#
#-----[ SAVE & CLOSE ALL FILES ]--------------------------
#
#End


Thanks very much,

Patricia
User avatar
Patricia    
STG Moderator
STG Moderator
 
Posts: 833
Joined: 09 Feb 2007, 08:27
Location: latitude: 51.00 - longitude: 5.87
Gender: Female

Re: Links in new window

Postby IPB_Refugee » 03 Oct 2007, 05:21

Hi Patricia,

this is easy to do with the following great MOD: [BETA] Prime Links - Classify Locals & Target Externals

Just look at the first few lines of prime_links.php - there you will find an option for hiding the referer.

Regards
Wolfgang
User avatar
IPB_Refugee    
Lt. Jr Grade
Lt. Jr Grade
 
Posts: 100
Joined: 21 Jun 2007, 03:24
Location: Austria, EU
Gender: Male

Re: Links in new window

Postby Patricia » 03 Oct 2007, 09:48

IPB_Refugee wrote:Hi Patricia,

this is easy to do with the following great MOD: [BETA] Prime Links - Classify Locals & Target Externals

Just look at the first few lines of prime_links.php - there you will find an option for hiding the referer.

Regards
Wolfgang



WOW, Wolfgang, thanks for that, works like a charm. :thumbsup: :yahoo:


Thanks for your help

Patricia
User avatar
Patricia    
STG Moderator
STG Moderator
 
Posts: 833
Joined: 09 Feb 2007, 08:27
Location: latitude: 51.00 - longitude: 5.87
Gender: Female

Re: Links in new window

Postby IPB_Refugee » 03 Oct 2007, 10:50

Glad I could help you. :hello: I love this MOD, too.

(I see you have edited your post. So I think the mentioned problem doesn't occur anymore. I have tested it yet and primehalo's MOD also works with external links in quotes - regardless if they are posted with BBCode [url ] or as magic URLs.)

Regards
Wolfgang
User avatar
IPB_Refugee    
Lt. Jr Grade
Lt. Jr Grade
 
Posts: 100
Joined: 21 Jun 2007, 03:24
Location: Austria, EU
Gender: Male

Re: Links in new window

Postby Patricia » 03 Oct 2007, 11:11

IPB_Refugee wrote:Glad I could help you. :hello: I love this MOD, too.

(I see you have edited your post. So I think the mentioned problem doesn't occur anymore. I have tested it yet and primehalo's MOD also works with external links in quotes - regardless if they are posted with BBCode [url ] or as magic URLs.)

Regards
Wolfgang


Hi Wolfgang,

Yes I edited the post, I saw that the magic URLs doesn´t work with the Quote tags, but that only affected older posts with the Quote tags. New posts with external links inside Quote tags works.

Thanks again,

Patricia
User avatar
Patricia    
STG Moderator
STG Moderator
 
Posts: 833
Joined: 09 Feb 2007, 08:27
Location: latitude: 51.00 - longitude: 5.87
Gender: Female

Re: Links in new window

Postby jdh » 03 Oct 2007, 14:12

patsi32 wrote:
IPB_Refugee wrote:Glad I could help you. :hello: I love this MOD, too.

(I see you have edited your post. So I think the mentioned problem doesn't occur anymore. I have tested it yet and primehalo's MOD also works with external links in quotes - regardless if they are posted with BBCode [url ] or as magic URLs.)

Regards
Wolfgang


Hi Wolfgang,

Yes I edited the post, I saw that the magic URLs doesn´t work with the Quote tags, but that only affected older posts with the Quote tags. New posts with external links inside Quote tags works.

Thanks again,

Patricia
I think that is because it is saved in the database as HTML to cut down load time. It'd make sense. I don't know how fixable this is, unless you edit all the posts and resubmit each of them, which takes time.
Iron helmets will not save
Even heroes from the grave.
Good men's blood will drain away
while the wicked win the day.
User avatar
jdh    
STG Support Team
STG Support Team
 
Posts: 1508
Joined: 05 May 2007, 08:04
Location: Wisconsin
Gender: Male
phpBB Knowledge: 7

Re: Links in new window

Postby Kjell » 03 Oct 2007, 16:06

Back to basic :P
Kjelle
My work - My farm - Ware I live - phpBB support Sweden
"The globe is round, think global", My rules: Be teased is okay on a funny way ;)
User avatar
Kjell    
Supporter
Supporter
 
Posts: 490
Joined: 14 Feb 2007, 13:09
Location: Nordic of Sweden
Favorite Team: NHL N-ville,Forsberg
Gender: Male
phpBB Knowledge: 8

Next

Return to Tutorials and How-Tos

Who is online

Users browsing this forum: No registered users and 3 guests