Activity Module

One of the most important features of a social network is that page that lets you see what people you know are doing. On Facebook, the first page you see when you login is the News Feed – a list of everything that your friends have done recently.

Activity is a Drupal module for creating a page like that. It lets you see when people sign up, make comments, post content, join groups (with Organic Groups), or become friends (with User Relationships).

Once you download the module (along with the required Tokens module, which lets you change the activity messages), enable it and its submodules (comment activity, node activity, etc). You’ll probably want to visit the Drupal permissions page and give authenticated users permission to view activity and comment on it as well.

In order to try it out, logout as admin (Activity doesn’t log any actions by the admin user), login as a regular user, and make some posts and comments. Then you can visit the /activity page to see your activity.

If you don’t want that many activities showing up, you can visit the Activity Settings page (/admin/settings/activity) and disable some types of messages. You can also change their wording to fit with your site better.

Adding User Pictures to the Messages

Adding user pictures to messages is simple. If you haven’t enabled user pictures on the site yet, go to User Settings (/admin/user/settings) and turn them on. Then go to Activity Settings (/admin/settings/activity) for Nodes or Comments to edit the messages. You can now use [author-picture] in the message text to insert the user picture.

Adding the Node Teaser to the Message

For MyFishingFacts, we wanted users to be able to see new content right inside of the activity stream. Since Activity doesn’t provide a way to do this, we re-themed the message in our code, replacing it with the node teaser.

You can modify the messages in your theme’s template.php file by overriding theme_activity. In this example, we’ll check for a user creating a page, load the teaser, and insert it into the message.

<?php
function phptemplate_activity($message, $item) {  

 
// Check if this is a page node being created.
 
if ($item['type''page' && $item['operation''insert') {
   
   
// Load the node
   
$node = node_load(array('nid' => $item['data']['node-id']));
       
node_view($node, true, false, false);

        
// Add the teaser text to the activity message
   
$message .= '<em>'. $node->teaser .'</em>';
    }
   
    return
$message;
}
?>

Put that in your template.php file, clear the Drupal cache, and node teasers should start showing up in the activity stream when you create a new page.

You can also use this method for things like inserting user pictures from the Content Profile module, or changing the layout of the activities table (using theme_activity_table).