There is a great discussion at drop.org about backlinks with some cool and interesting functions. However, Dries our "Keep It Simple" leader, challenged the group to put something simple together quickly.

I'm at work and really shouldn't spend much time on this, but came up with the following code to add to the admin module. I can't test it at work, but maybe someone will take the batton and finish this off.

Here's the code snippet:

function statistics_table_backlink_block($query) {
  $result = db_query($query);

  $output .= "<table border="1" cellpadding="3" cellspacing="0">n";
  $output .= " <tr><th>URL</th><th>number</th></tr>n";
  while ($referrer = db_fetch_object($result)) {
    $output .= "<tr><td><a href="". check_output($referrer->url) ."" title="". substr(check_output($referrer->url), 0, 100) ."
">". substr(check_output($referrer->url), 0, 20) ."</a></td><td>". check_output($referrer->count) ."</td></tr>";

  }
  $output .= "</table>n";

  return $output;
}

function statistics_table_backlink_block() {
  $block[0]["subject"] = t("Who's Linking Here?");
  $block[0]["content"] = statistics_table_3("SELECT url, COUNT(url) AS count FROM referrer WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' GROUP BY url ORDER BY count DESC LIMIT 10, timestamp");

  $block[0]["info"] = t("Links Back to Referrers");
  return $block;
}

Comments

moshe weitzman’s picture

Priority: Major » Normal

Joe is still asking for some SQL help. I've got answers for his other questions.

there are a couple strategies for determining the node you are looking at. the simplest is this one:

$currenturl = request_uri();

The only problem with that, is that there are several URLs in Drupal which all lead to the same node. You might miss a few hits and undercount a bit. You'd have to experiment to know how bothersome the undercount is.

A different approach is to do search or parse the querystring and look for 'id=x'. Then in your SQL query, do a WHERE url CONTAINS 'in=x'. This would overcount a bit since views of a project or a feed with the same 'id' will also match ... I tried to code this approach but got stuck on how to parse a querystring. help.

TheLibrarian’s picture

Component: Code » other

Correct me if I'm wrong, but this is simply TrackBack with another name. In fact, the site that originally introduced backlinks now recommends the use of TrackBack [1]. I'm setting this to closed because we now have a trackback.module.

[1] http://www.disenchanted.com/dis/linkback.html

Boris Mann’s picture

I was just talking about this today. I would much rather have "backlinks" than Trackback. Not all systems support Trackback, and it certainly doesn't cover things like people posting links to your items in discussion forums, etc.

Actually, what I would like to see is a block that allows you to display referrer links, along with tools in statistics (or as part of a contrib module) to manage the display of referrer links, including the ability to block/ban certain sites.

killes@www.drop.org’s picture

Project: Drupal core » TrackBack
Component: other » Other

I don't know the differences between trackback and backlinks but I think that - if the need exists - the trackback moduel should be extended to cover both.

ankur’s picture