How to make Mint's BirdFeeder work in Drupal 6

Mint has a plug-in called BirdFeeder that collects statistics about RSS feeds - number of subscribers, clicked posts, etc.

Unfortunately, it is not easy to install in Drupal, since the formatting of RSS in Drupal is hardcoded, so there is no template to modify. This post describes how to modify node.module to make BirdFeeder work in Drupal 6.

First, a word of warning. To change core files like node.module is generally not a good idea - anything you do will be wiped out the next time you update Drupal. If you only have one or a few RSS feeds from your site, it probably is a better idea to use FeedBurner to get the statistics. (There is also a FeedBurner module, but I'm not sure how much statistics it provides. Another alternative may be to adapt the atom.module Update: Keep an eye on the Mint module. It's still being developed, but BirdFeeder support (without changing core files) is in the plans.)

If you are not discouraged, take these steps:

  • Download and install BirdFeeder files.
  • Backup your Drupal and Mint databases.
  • Make a backup of your node.module file (in /modules/node)
  • Replace node.module with this file
  • Optional: Modify the BirdFeedTitleCleaner function, to make the titles to your liking.
  • Activate BirdFeeder in Mint's interface

Your feed statistics should now start to pour into Mint

In case you're interested in the details, these are the modifications I've made to node.module:

Between

$namespaces = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'); 
$items = ''; 

I added this code:

<?php
/* BirdFeeder */
 
global $Mint;
  if (!isset(
$channel['title'])){     // Drupals main feed does not provide a title
   
$channel['title'] = variable_get('site_name', 'Drupal');  // Make a title for BirdFeed
 
}
 
define('BIRDFEED', BirdFeedTitleCleaner(check_plain($channel['title']))); // Short feed names makes the pane in
                                                // BirdFeed easier to read. If you want to modify what name is
                                                // displayed, use BirdFeedTitleCleaner().
 
include_once('feeder/index.php');   // Among other things this creates the BirdFeed object used below.
  /**/
?>

A bit further down

$items .= format_rss_item($item->title, $item->link, $item_text, $extra);
was replaced with:
<?php
   
/* BirdFeeder */
   
$items .= format_rss_item_for_BirdFeeder($item->title, $item->link, $item_text, $extra, $BirdFeeder);
                   
// format_rss_item_for_BirdFeeder() will format the link the way BirdFeeder likes it
    // Original: $items .= format_rss_item($item->title, $item->link, $item_text, $extra);
    /**/
?>

Finally, these two functions where added:

<?php
/**
* Cleans & shortens titles for feeds that are to be monitored by Mint/BirdFeed.
*
* (No need to use if you like the titles as they are.)
*/
function BirdFeedTitleCleaner($title){
  if (
$title == variable_get('site_name', 'Drupal') ){
    return
t('Main');
  } else {
   
$cleaned_title = str_replace(variable_get('site_name', 'Drupal').' - ', '', $title);
    return
$cleaned_title;
  }
}

/**
* Format a single RSS item - BirdFeeder style.
*
* Adapted from the original format_rss_item (in includes/common.inc).
*/
function format_rss_item_for_BirdFeeder($title, $link, $description, $args = array(), $BirdFeeder) {
 
$output = "<item>\n";
 
$output .= ' <title>'. check_plain($title) ."</title>\n";

 
// Modification for BirdFeeder
 
$output .= ' <link>'. $BirdFeeder->seed($title , check_url($link), TRUE) ."</link>\n";
 
// Original: $output .= ' <link>'. check_url($link) ."</link>\n";

 
$output .= ' <description>'. check_plain($description) ."</description>\n";
 
$output .= format_xml_elements($args);
 
$output .= "</item>\n";

  return
$output;
}
?>

Läs mer: