Please upgrade here. These earlier versions are no longer being updated and have security issues.

Disable rel="nofollow" on posts by certain users

edited December 2010 in Vanilla 2.0 - 2.8

I can disable the nofollow attribute by removing it from line 543 in class.format.php:

$Result = <<<EOT <a href="$Pr$Url" target="_blank" rel="nofollow">$Pr$Url</a> EOT;

If I do this it affects all links.

My goal is to track down the code which calls Gdn_Format::Html when outputting the forum post, so I can find out the UserID of the post which vanilla is outputting, and then adjust the nofollow attribute based on the UserID. Crude and not very extensible but might be the start of a future plugin (ie: set certain roles to have nofollow links..)

Anyone point me in the right direction? I'll keep hunting and post if I find it.

here is the forum I'm trying to mod.

Another option could be: if preg_match('#'.$_SERVER['HTTP_HOST'].'#i',$Url) dont use nofollow but I'd like the nofollow to a few other domains on my posts, and by userid makes more sense to me.


EDIT: hmm seems this will be more difficult than first expected. if the post contains html A links then they will be be parsed by htmLawed which adds it's own nofollow attribute. Seems this can be controlled by line 40 in class.htmlawed.plugin.php:
$Config = array( 'anti_link_spam' => array('`.`', ''),
got it sortov working - it will nofollow external links as opposed to all links:
$Config = array( 'anti_link_spam' => array('`^((?!'.preg_quote($_SERVER['HTTP_HOST'],'`').').)*$`i', ''),


  • My changes:

    class.format.php, line 24 add:

    /** * Flag to put rel="nofollow" in links or not */ public static $DisplayNoFollow = true;

    class.format.php, line 410, change to:

    $nofollow = (self::$DisplayNoFollow) ? ' rel=\"nofollow\"' : ''; $Mixed = preg_replace( "/ (?<!<a href=\") (?<!\")(?<!\">) ((https?|ftp):\/\/) ([\@a-z0-9\x21\x23-\x27\x2a-\x2e\x3a\x3b\/;\x3f-\x7a\x7e\x3d]+) /msxi", "<a href=\"$0\" target=\"_blank\"$nofollow>$0</a>", $Mixed );

    class.format.php, line 550, change to:

    $nofollow = (self::$DisplayNoFollow) ? ' rel="nofollow"' : ''; $Result = <<<EOT <a href="$Pr$Url" target="_blank"$nofollow>$Pr$Url</a> EOT;

    class.htmlawed.plugin.php, line 50, add this:

    if(Gdn_Format::$DisplayNoFollow){ // display rel="nofollow" on all links. $Config['anti_link_spam'] = array('`.`', ''); }else{ // never display rel="nofollow" $Config['anti_link_spam'] = array('',''); }

    helper_functions.php, line 26 add:

    /** * All users except UserID 1 have nofollow on their links. */ Gdn_Format::$DisplayNoFollow = ($Author->UserID!=1);
Sign In or Register to comment.