[RC1] Prime Links - Classify Locals & Target Externals

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Suggested Hosts
User avatar
primehalo
Former Team Member
Posts: 2991
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by primehalo »

Sure, just use preg_match instead of strpos.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!
nemmar
Registered User
Posts: 85
Joined: Mon Jun 13, 2005 2:07 pm

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by nemmar »

primehalo wrote:Sure, just use preg_match instead of strpos.
I tried that but I got errors in the post pages online.
I replaced line 343 of the prime_links.php page which had this code:
if ($is_local && (strpos($href, 'asp-rel-articles-01') !== false || strpos($href, 'asp-rel-articles-02') !== false || strpos($href, 'asp-rel-articles-03') !== false || strpos($href, 'asp-rel-articles-04') !== false || strpos($href, 'asp-rel-articles-05') !== false))

Here is the changed line of code:
if ($is_local && (preg_match($href, 'asp-rel-articles') !== false))

Here is the error that displayed at the top of the post pages online after I made this code change:
[phpBB Debug] PHP Notice: in file /includes/prime_links.php on line 343: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash
[phpBB Debug] PHP Notice: in file /includes/prime_links.php on line 343: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3826: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3247)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3828: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3247)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3829: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3247)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3830: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3247)

I edited the php file in Notepad++ so I don't think it's the Byte Order Marks problem you told me about last time. Can you tell me what I did wrong? Thanks.
User avatar
primehalo
Former Team Member
Posts: 2991
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by primehalo »

You have to use a regular expression, not just the string 'asp-rel-articles-02'. Please see the documentation for the preg_match function: http://php.net/manual/en/function.preg-match.php
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!
nemmar
Registered User
Posts: 85
Joined: Mon Jun 13, 2005 2:07 pm

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by nemmar »

primehalo wrote:You have to use a regular expression, not just the string 'asp-rel-articles-02'. Please see the documentation for the preg_match function: http://php.net/manual/en/function.preg-match.php
Okay, I checked that linked page about preg_match but I'm not sure how the line of code should be. For example, should I just use asp-rel-article-??
with the ?? referencing 01, 02, 03, etc. in the folder names?

if ($is_local && (preg_match($href, 'asp-rel-articles-??') !== false))
User avatar
primehalo
Former Team Member
Posts: 2991
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by primehalo »

Here is a good guide on how regular expressions work:
http://www.webcheatsheet.com/php/regula ... ssions.php

Also, with preg_match, the pattern comes first, then the subject. It's the opposite order from strpos.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!
Bigwbmstr
Registered User
Posts: 3
Joined: Thu Jan 17, 2008 10:09 pm

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by Bigwbmstr »

Found a small bug. On this line in prime_links.php in the function modify_links:

Code: Select all

preg_match_all('#(<a[^>]+?>)(.*?</a>)#i', $message, $matches, PREG_SET_ORDER);
The problem here is if the board admin has setup any additional BBCodes that allow the insertion of any other tags that start with the letter "a". For example on our board we have a BBCode that uses the acronym tag and because of that the next link that follows the acronym tag is actually skipped because the regex is taking way more than it should. The fix is very simple, simply add a space in your preg_match_all to ensure its just the a (anchor) tag and no other tags that start with the letter a. So here is the fixed code:

Code: Select all

preg_match_all('#(<a [^>]+?>)(.*?</a>)#i', $message, $matches, PREG_SET_ORDER);
Tested it on our board and it has indeed fixed the problem. Hope that helps :)
User avatar
primehalo
Former Team Member
Posts: 2991
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by primehalo »

Thanks.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!
phatchopolis
Registered User
Posts: 166
Joined: Mon May 29, 2006 11:40 pm

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by phatchopolis »

This MOD sounds great. I had one question. When someone posts an image in my forum by default when it's clicked they're taken away from the forum and too whichever imagehost the photo is stored with. Will this mod allow those to open in an external tab as well?
lovelysummer
Registered User
Posts: 437
Joined: Fri Mar 20, 2009 1:49 pm

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by lovelysummer »

Hello, Prime halo,
Is this one same as this mod ? http://www.phpbb.com/community/viewtopi ... 9&t=875585

Tks.
User avatar
primehalo
Former Team Member
Posts: 2991
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by primehalo »

phatchopolis wrote:This MOD sounds great. I had one question. When someone posts an image in my forum by default when it's clicked they're taken away from the forum and too whichever imagehost the photo is stored with. Will this mod allow those to open in an external tab as well?
I'm not 100% positive, but probably.
lovelysummer wrote:Hello, Prime halo,
Is this one same as this mod ? http://www.phpbb.com/community/viewtopi ... 9&t=875585

Tks.
Same MOD, but probably different version.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!
conan_troutman
Registered User
Posts: 222
Joined: Mon Jul 19, 2010 11:06 am

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by conan_troutman »

I have a problem....

when I click links in profile (uses website)

instead of getting www.example.com I get http://www.example.com/onclick=
User avatar
primehalo
Former Team Member
Posts: 2991
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by primehalo »

It appears that it was not installed correctly. Please review the install user website links.xml instructions file and make sure all instructions were followed properly.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!
conan_troutman
Registered User
Posts: 222
Joined: Mon Jul 19, 2010 11:06 am

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by conan_troutman »

primehalo wrote:It appears that it was not installed correctly. Please review the install user website links.xml instructions file and make sure all instructions were followed properly.

aye... I put the code for external links before the " instead of after "

cheers
User avatar
umarizal
Registered User
Posts: 177
Joined: Mon Mar 17, 2008 2:03 am
Location: São Paulo - SP - Brasil
Name: Leandro dos Santos

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by umarizal »

Hi PrimeHalo!

I had installed on your mod phpBB 3.0.6 and it worked perfectly. All external links with rel="nofollow".

I upgraded the forum to 3.0.7pl1,using a clean template Prosilver.

I did all the installation steps again using the latest version available on their website (v 1.2.9).

The external links posted in threads, posts or signature, is correct, with rel="nofollow".

Web site links of members, in profile beside the post or in the list of members not present rel="nofollow". Why?

I want to make ALL external links use rel="nofollow", wherever they appear (message, profile, signature, member list, etc.)

My site: http://www.guiadaobra.net/forum/
EN: Do to others what you would want them to do to you.
ES: Haz a los demás todo lo que quieras que te hagan a ti.
PT: Faça aos outros o que você gostaria que fizessem a você.
User avatar
primehalo
Former Team Member
Posts: 2991
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA

Re: [RC1] Prime Links - Classify Locals & Target Externals

Post by primehalo »

My MOD was designed primarily for links within posts and signatures, it never processed all links everywhere.

If you want a quick and dirty fix, open includes/prime_links.php, find:

Code: Select all

                $external_target = (USE_TARGET_ATTRIBUTE === true) ? (' target="' . EXTERNAL_LINK_TARGET . '"') : (' onclick="this.target=\'' . EXTERNAL_LINK_TARGET . '\';"');
 
And after, add this:

Code: Select all

                $external_target .= EXTERNAL_LINK_REL ? (' rel="' . EXTERNAL_LINK_REL . '"') : ''; 
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!

Return to “[3.0.x] MODs in Development”