rakaz

about standards, webdesign, usability and open source

Google to the rescue!

In an attempt to combat comment spam, Google, MSN, Yahoo and a number of other companies have agreed to support the rel=”nofollow” attribute on links.

If you’re a blogger (or a blog reader), you’re painfully familiar with people who try to raise their own websites’ search engine rankings by submitting linked blog comments like “Visit my discount pharmaceuticals site.” This is called comment spam, we don’t like it either, and we’ve been testing a new tag that blocks it. From now on, when Google sees the attribute (rel=”nofollow”) on hyperlinks, those links won’t get any credit when we rank websites in our search results. This isn’t a negative vote for the site where the comment was posted; it’s just a way to make sure that spammers get no benefit from abusing public areas like blog comments, trackbacks, and referrer lists.

I’ve modified Nucleus, which I am using on my blogging software, to support the rel=”nofollow” attribute and hope others will follow too. Instructions on how to modify Nucleus are inside…

COMMENT.php

First find the COMMENT.php file in the nucleus/libs directory. At the bottom of this file you will find the createLinkCode() function which you will need to modify.

At the bottom of the createLinkCode() function, on line 126 or so, you will find something that looks like this:

return $pre . '<a href="'.$linkedUrl.'">'.shorten($displayedUrl,30,'...').'</a>' . $post;

Simply modify this line to this:

return $pre . '<a href="'.$linkedUrl.'" rel="nofollow">'.shorten($displayedUrl,30,'...').'</a>' . $post;

COMMENTS.php

Next you need to open the COMMENTS.php file in the same directory and go to the parse_userlink() function. On or around line 378 you’ll find the following line:

echo '<a href="'.$this->currentComment['userlinkraw'].'">'.$this->currentComment['user'].'</a>';

Modify this line to:

echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';

ADMIN.php

Finally you need to open the ADMIN.php file in the same directory and go to the action_commentedit() function. On or around line 1326 you’ll find the following line:

$comment['body'] = eregi_replace("<a href=['\"]([^'\"]+)['\"]>[^<]*</a>","\\1",$comment['body']);

Modify this line to:

$comment['body'] = eregi_replace("<a href=['\"]([^'\"]+)['\"]( rel=\"nofollow\")?>[^<]*</a>","\\1",$comment['body']);

And you’re done!

20 Responses to “Google to the rescue!”

  1. xiffy wrote on January 19th, 2005 at 1:30 pm

    rakaz, you missed out the userid link, if you want that to be non-page-ranking
    as well, just modify line 378 in COMMENTS.php (note the plural S)
    from
    echo ‘currentComment['userlinkraw'].
    ‘">’.$this->current Comment['user'].’
    ‘;
    into
    echo ‘currentComment['userlinkraw'].
    ‘">’.$this->current Comment['user'].’
    ‘;

  2. xiffy wrote on January 19th, 2005 at 1:31 pm

    hmm, nucleus doesn’t like this code at all…

  3. rakaz wrote on January 19th, 2005 at 2:20 pm

    Thanks xiffy… I’ve updated the instructions to include the userid link.

  4. Moe wrote on January 19th, 2005 at 11:58 pm

    I did just the same this morning. But the thing is, spammers won’t care if you or I do so, unless it’s included in all future releases of Nucleus.
    Just my 2c ;-)

  5. xiffy wrote on January 20th, 2005 at 11:03 am

    rakaz, have you found a solution for line 1326 in ADMIN.php where the comment is retrieved for editing? The reverse proces; changin the link back to text is borked with the applied patches. Hadn’t got time to investigate and patch this bug yet myself …

  6. rakaz wrote on January 20th, 2005 at 11:05 am

    hmm, didn’t think of that… I’ll take a look at it in a moment

  7. rakaz wrote on January 20th, 2005 at 11:12 am

    Added extra instruction for ADMIN.php. Editing links should work again…

  8. Nucleus Forum wrote on January 20th, 2005 at 11:24 am

    Is this something that could easily be added to Nucleus via a plugin or a template?

  9. xiffy wrote on January 20th, 2005 at 11:24 am

    :-) your fast!

  10. Nucleus Dev wrote on January 20th, 2005 at 12:48 pm

    In the “Preventing comment spam” post on the Google Blog, Google has now officially announced that they will longer be consider links attributed with rel=”nofollow” when calculating pagerank scores.

  11. Roel wrote on January 20th, 2005 at 2:43 pm

    Nice work! I will implement this tonight. :)

  12. Joaquin wrote on January 20th, 2005 at 4:22 pm

    I just implemented it. It’s applied to new comments only, right?

  13. admun wrote on January 20th, 2005 at 4:24 pm

    Good stuff rakaz! It works great

  14. admun wrote on January 20th, 2005 at 4:26 pm

    Joaquin,

    My understanding is it works for old comment as well. I tested it on my blog from a old post and it works.

    cheers

  15. Pan Admun Republic of Western Blog wrote on January 20th, 2005 at 4:28 pm

    Spammers,

    Go away from me! It’s not going to help your links’ ranking by spamming here.

    rakaz

  16. rakaz wrote on January 20th, 2005 at 4:41 pm

    admun, joaquin: Because text of comments and any URL contained in the text are stored in HTML form in the database and not processed before being displayed, this won’t work for older comments. However, if you edit an existing comment it will add the rel="nofollow" attribute.

    The URL of the comment (if specified) is processed at the time it is displayed, so rel="nofollow" will be added to the URL for all comments, even older ones.

  17. Joaquin wrote on January 20th, 2005 at 5:17 pm

    OK! Thanks for this post, by the way. :)

  18. MSC wrote on February 8th, 2005 at 11:19 am

    Why not add a PreAddComment plugin for existing 3.x versions of Nucleus that would replace any links with the nofollow version of them? Admittedly, it wouldn’t solve the problem for existing commentspam, but any new links in comments would be properly nofollowed.

  19. blitzsite.ru wrote on August 26th, 2005 at 1:25 pm

    nice

  20. Stelios wrote on May 24th, 2007 at 3:10 am

    Cool design, great info!