Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Biology Forums - huhtikuu 16, 2014, 01:06:57 AP

Otsikko: Adding nofollow to all external links
Kirjoitti: Biology Forums - huhtikuu 16, 2014, 01:06:57 AP
In Subs.php, I'm trying to add rel="nofollow" to all links that don't possess my URL ($boardurl).

For example, if I linked cnn.com, the html would be <a rel="nofollow" href="cnn.com", whereas if I linked my own site MYURL.com, the html wouldn't contain rel="nofollow".

Can someone tell me how to accomplish this? This is what I've achieved so far, but it's causing all links to contain rel="nofollow"

global $boardurl;
if(strpos($message, '<a href') !== false)
$message = preg_replace('~(<a)( href="(?!' . preg_quote($boardurl) . ')(?:[^"]*?)"(?:[^>]*?)\>(?:.*?)</a>)~i', '$1 rel="nofollow"$2 ', $message);


This is going near the end of function parse_bbc. This is for 1.1.19.

Any suggestions?
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: margarett - huhtikuu 20, 2014, 09:36:51 IP
Actually I'm pretty sure that a mod for this did exist. If only I could find it...
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: Deaks - huhtikuu 20, 2014, 10:05:08 IP
You mean like this one:

http://custom.simplemachines.org/mods/index.php?mod=1236

And

http://custom.simplemachines.org/mods/index.php?mod=1237
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: Biology Forums - huhtikuu 21, 2014, 02:26:17 AP
http://custom.simplemachines.org/mods/index.php?mod=1236

That's for all links.

http://custom.simplemachines.org/mods/index.php?mod=1237

That's a BBCode

I should have made it clear that I want it to occur automatically :-\
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: margarett - huhtikuu 21, 2014, 05:35:23 AP
I checked now, there was really an unapproved mod. :(
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: Biology Forums - huhtikuu 21, 2014, 12:19:15 IP
Lainaus käyttäjältä: margarett - huhtikuu 21, 2014, 05:35:23 AP
I checked now, there was really an unapproved mod. :(

Can you provide the link?
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: Deaks - huhtikuu 21, 2014, 12:31:47 IP
if its un-aproved a link wont work
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: Illori - huhtikuu 21, 2014, 12:39:20 IP
i think he was talking about http://www.simplemachines.org/community/index.php?topic=510778.0 which became a mod and the author and mod are now gone.
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: margarett - huhtikuu 21, 2014, 02:15:27 IP
Exactly :)
Otsikko: Re: Adding nofollow to all external links
Kirjoitti: Biology Forums - huhtikuu 22, 2014, 01:20:30 AP
What a shame.