Neil Turner's Blog

Blogging about technology and randomness since 2002

Friend or foe

I’ve come up with a bit of PHP which decides whether a particular commenter is a ‘friend’ or a ‘foe’. If they are a ‘friend’, then when they post their URL with their comment, the URL will not be posted as a redirect. If they are a ‘foe’, then their URL will redirect.
A ‘friend’, by my definition, is someone who regularly offers useful or insighting comments. I have taken down the URLs of the sites of those commenters and then fed them into a PHP script, so that if they post a comment, the URL will not redirect. Any other URLs will redirect.
Update: The original code I posted wouldn’t actually work. Use the new code below which does work.


This is the code I used (with the URLs removed for brevity):

<?
function friendorfoe($url)
{
$urls=array('www.example.com','test.blogspot.com');
$imax=(count($urls) - 1);
for ($i=0; $i<=$imax; $i++)
{
if (ereg('^http://' . $urls[$i],$url))
{
return true;
}
}
}
?>

If you were to deploy this script, you would add your friends’ URLs to the array, and then save this as a file. Then, in your Individual Entry Archive, you would include this file at the top, and then, in pace of the code you use to display the author’s site, paste this:

<?
if (friendorfoe("<$MTCommentURL$>"))
echo('<$MTCommentAuthorLink show_email="0" no_redirect="1"$>');
else
echo('<$MTCommentAuthorLink show_email="0"$>');
?>

The code works by iterating through each item in the array and then uses a regular expression to test to see if the URL that has been typed in matches an item in the array. If it does, the function returns true, otherwise it is false. It would take into account slight variations in the URL – for example ‘http://www.metzener.com/dave’ and ‘http://www.metzener.com/chalkboard’ would both be seen as ‘friends’, but it isn’t yet powerful enough to know that URLs do or don’t need ‘www’ in front of them.
At the moment, I have around 30 URLs in there (taken from the 30 most frequent commenters here) but I will add more as time goes on. This means that regular commenters get the bonus of a bit of extra Google PageRank; ‘foes’ – those that don’t comment here often – do not. And that ‘foes’ category includes spammers.
If you don’t post here very much, don’t take this as an indication that your posts are not worth anything – they are. But think of this as a kind of ‘loyalty club’ for those who do post regularly.

12 Comments

  1. Neat idea.
    But an array doesn’t seem like the best way to store a large amount of URL’s.
    Maybe a database would be a better way?

  2. Maybe. But I’m not storing that many URLs – as I said, it’s currently around 30 and I don’t imagine it’ll be more than double that any time soon.
    Certainly a larger system would do well to be based around a database.

  3. Great idea! I’d implement something similar but Google hasn’t indexed Pink Socks!

  4. Great idea Neil, the only question is do the comment spammers care? I still get comment spam and I’m running MT 2.x and the urls are hidden.
    All the same though I like the idea.

  5. Friend or Foe

    Friend or foe…

  6. Can I be your friend? πŸ˜‰
    Heh Neil this is a very neat idea! One of the reasons I didn’t turn on comments redirection was because I wanted to give my loyal readers (all 10 of them) the benefit of PageRank for commenting (hoping that that would somehow cause them to de-lurk).

  7. Cheah: Sure πŸ™‚
    I’ve actually corrected the code since its initial implementation to make it actually work (which always helps πŸ™‚ ) so if you deployed it then you’ll need to update it. My tip would be to put the more common URLs in first as then it will reduce the processing time.

  8. i’m presuming I’m in the list of friends πŸ™‚
    It’s weird in that the number of posts I’ve made on other blogs, yet they don’t very often show up in google..
    As to the spammers posting on url removed sites, I think theyir scripts are not clever enough to realise that and they just dump in data from keywords found in google such as “powered by movabletype”.
    (I hope this post comes out ok as my browser is doing weird stuff and I can’t actually see what I’m typing!

  9. Tweaking MTCommentAuthorIdentity

    There are several features of the <MTCommentAuthorIdentity> that annoys me. target=”_blank” I absolutely hate links opening in new windows/tabs without my permission. My view on this is that if I want something to open in a new window…

  10. Wow! That’s cool. But if there are a number of ‘friends’ like 1000, then what happens???

  11. I set up a TypeKey account and am attempting to use it here. When I click on the “sign in” above, some redirection occurs, but then I’m presented with a blank comment form. Seems like name / e-mail / URL would pre-fill. Hmmm…. — Fish