Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Neo_TE in Juli 17, 2013, 02:04:33 NACHMITTAGS

Titel: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in Juli 17, 2013, 02:04:33 NACHMITTAGS
A better implementation of this feature is available in this thread, http://www.simplemachines.org/community/index.php?topic=510778.0.



ZitatWarning:
FYI, this trick adds nofollow for all automatically parsed links (i.e. links that are not wrapped within url or iurl tags), irrespective of whether they're internal or external links.

To overcome that issue, I made a mod (its yet to be approved) and you may checkout the features of that mod in this link, http://www.simplemachines.org/community/index.php?topic=508093.


Tip/Trick to add "nofollow" option for external links. Do the following edits in ~/Sources/Subs.php


Find:
Code (find) Auswählen
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',

Replace:
Code (replace) Auswählen
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<a href="$1" class="bbc_link" target="_blank" rel="nofollow">$1</a>',




Find:
Code (find) Auswählen
'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="bbc_link" target="_blank">',

Replace:
Code (replace) Auswählen
'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="bbc_link" target="_blank" rel="nofollow">',




How-To
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Colin in Juli 17, 2013, 02:22:46 NACHMITTAGS
This is awesome. Thank you so much for taking the time to post this xPandax.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Mick. in Juli 17, 2013, 04:43:54 NACHMITTAGS
Nicely done.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Mick. in Juli 17, 2013, 04:45:02 NACHMITTAGS
Reminds of Wikipedia. Their out links are the same. No follow.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in Juli 18, 2013, 12:53:19 VORMITTAG
Thank you. :)
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in Juli 20, 2013, 02:04:24 VORMITTAG
Zitat von: BaoLePhuong in Juli 19, 2013, 10:51:56 NACHMITTAGS
This is awesome. Thanks. I love it :D
I'm glad to hear that and you're welcome.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: gr8shivam in Juli 21, 2013, 01:25:36 VORMITTAG
I have my forum on a subdomain. Will this trick change the links that are linking to my domain to nofollow?
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Colin in Juli 21, 2013, 04:21:08 VORMITTAG
Zitat von: gr8shivam in Juli 21, 2013, 01:25:36 VORMITTAG
I have my forum on a subdomain. Will this trick change the links that are linking to my domain to nofollow?

Yes, it will for all links.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in Juli 21, 2013, 08:38:55 VORMITTAG
Since this trick, adds nofollow for all automatically parsed links, irrespective of whether they're internal or external links, I made a mod that differentiates the internal links from external links and

Check this thread, http://www.simplemachines.org/community/index.php?topic=508093.  Feedback appreciated. Thanks.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: SKSLink.com in August 03, 2013, 02:11:18 NACHMITTAGS
My script code looks different for a version SMF 2.0.4:
   ),
         array(
            'tag' => 'iurl',
            'type' => 'unparsed_content',
            'content' => '<a href="$1" class="bbc_link">$1</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '
               $data = strtr($data, array(\'<br />\' => \'\'));
               if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
                  $data = \'http://\' . $data;
            '),
         ),
         array(
            'tag' => 'iurl',
            'type' => 'unparsed_equals',
            'before' => '<a href="$1" class="bbc_link">',
            'after' => '</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '
               if (substr($data, 0, 1) == \'#\')
                  $data = \'#post_\' . substr($data, 1);
               elseif (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
                  $data = \'http://\' . $data;
            '),
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in August 04, 2013, 03:50:00 VORMITTAG
Zitat von: SKSLink.com in August 03, 2013, 02:11:18 NACHMITTAGS
My script code looks different for a version SMF 2.0.4:

You searched for

'tag' => 'iurl',

You should actually search for 'tag' => 'url',


FYI, this trick adds nofollow for all automatically parsed links, irrespective of whether they're internal or external links.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Burke ♞ Knight in August 04, 2013, 12:10:41 NACHMITTAGS
Nice tip, my friend. :)
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in August 04, 2013, 11:06:08 NACHMITTAGS
Thank you very much.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: jackkbu in August 06, 2013, 02:15:58 VORMITTAG
Thanks for the knowledge.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in August 06, 2013, 03:40:12 VORMITTAG
Thank you very much.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Devpro in August 23, 2013, 06:55:05 VORMITTAG
This is great. And really useful. I love it.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Neo_TE in September 07, 2013, 06:02:45 VORMITTAG
A better implementation of this feature is available in this thread, http://www.simplemachines.org/community/index.php?topic=510778.0.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Cheat in Mai 22, 2016, 01:46:01 NACHMITTAGS
Sorry for the huge bump, but I had been struggling with making external links nofollow and internal ones followed, so I thought I would drop in and let everybody know how I did it.

1. Do what OP says. All links will be nofollow.

2. In Display.template.php of your template add the following code after:

// Show the post itself, finally!

Or really anywhere before the post body is rendered. For this next bit of code, I am checking for my site (sep7agon.net). You should replace the "sep7agon" and "net" with your respective domain name/TLD.


// Do some filters for external links...
        $temp_content = $message['body'];
        $preg_pattern = '~<a\shref\s?=\s?"http([^\.]+)sep7agon\.net([^>]+)>~';
        $temp_content = preg_replace_callback(
            $preg_pattern,
            function($match){
                return str_replace('rel="nofollow"', '', $match[0]);
            },
        $temp_content
        );
       
        $message['body'] = $temp_content;
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Biology Forums in Juni 11, 2016, 11:52:33 VORMITTAG
Thx
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Wellwisher in Juli 25, 2016, 10:39:16 NACHMITTAGS
Neo_TE made a mod of this trick, does anyone have it please? I can't be bothered to make edits?  :P Someone attach it here?

Went to the op link:
http://www.simplemachines.org/community/index.php?topic=510778.0

His Mod:
http://custom.simplemachines.org/mods/index.php?mod=3767

it says "Sorry but no mod was found"?
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Illori in Juli 26, 2016, 05:05:20 VORMITTAG
the mod was removed from the mod site and the package was removed. even if the package exists somewhere it cant be attached unless it has a license that allows it.
Titel: Re: [Tip/Trick] Add "nofollow" for external links
Beitrag von: Wellwisher in Juli 26, 2016, 05:36:21 VORMITTAG
Zitat von: Wellwisher in Juli 25, 2016, 10:39:16 NACHMITTAGS
Neo_TE made a mod of this trick, does anyone have it please? I can't be bothered to make edits?  :P Someone attach it here?

Went to the op link:
http://www.simplemachines.org/community/index.php?topic=510778.0

His Mod:
http://custom.simplemachines.org/mods/index.php?mod=3767

it says "Sorry but no mod was found"?

Found it, it's on Github and it's public domain software/ license:

https://github.com/LinuxPanda/SMF2.0Mod--Auto_-iurl-_For_Internal_Links_And_-nofollow-_For_External_Links

Interesting mod, will test it out when I have the time.  :)