Kroc / NoNonsenseForum

A free, open source, PHP-based simple discussion forum. It favours removing barriers to conversation rather than massaging egos. Download Here: https://github.com/Kroc/NoNonsenseForum/archive/master.zip
http://camendesign.com/nononsense_forum
Other
247 stars 34 forks source link

Adding link relation only for external links. #152

Closed Zegnat closed 12 years ago

Zegnat commented 12 years ago

Did some playing around with the link parsing after the discussion about opening links in a new window. Currently every link is given the nofollow status. I propose we only give this to external links, and make use of this difference to add external to the rel.

The following code is pretty much my quick-and-dirty fix. Milage may vary. Just putting it in here to illustrate my point. Starts at line 339 of functions.php of the current development branch.

    )) $text = substr_replace ($text, $replace =
        '<a href="'.($p=(@$m[2][0] ? 'mailto:'.$m[2][0]                     //is this an e-mail address?
                                   : ($m[1][0] ? $m[1][0] : 'http://')))    //has a protocol been given?
        //rest of the URL [domain . slash . everything-else]
        //(encode double-quotes without double-encoding existing ampersands; this is the PHP5.2.3 requirement)
        .htmlspecialchars ($m[3][0].@$m[4][0].@$m[5][0], ENT_COMPAT, 'UTF-8', false).'"'
        .($p.$m[3][0]!==FORUM_URL?' rel="nofollow external"':'').'>'
        .$m[0][0].'</a>',
        //where to substitute
        $m[0][1], strlen ($m[0][0])
    );

This means the CSS for themes can now target outgoing links with a[rel~="external"]. And JS can target these to open them in a new window/tab.

Kroc commented 12 years ago

Was indeed thinking of this, but thanks very much for going ahead and taking the initiative. I have no objection to the change so will integrate it at the next opportunity.