RT @lullabot: Cool! @leolaporte talks with @mettamatt and @jjeff about Lullabot and #Drupal on the @TWiT blog: http://t.co/cnzDOtvT
Activity Module Beta
Activity Module came about as a result of a need to show what your friends were doing on a site, something like what facebook does with your friends' news feed. The original idea came from the mind of quicksketch, coded by myself (with much help from quicksketch) then improved upon (5.x.3 branch) by robertDouglass.
I was asked to add a feature the other day that could have activity update in a fashion similar to the user reviews on the community tab of Netflix.com where you can just watch the list update all day. To accomplish this I first had to do two things, create a way to get activity in JSON format and then find some JavaScript to display it with an Ajax call. (AjaJ?)
So how does activity provide JSON data in order to do all this fun fancy stuff? Well, first it provides a path in the hook_menu(). There is a path for all activity ('activity/all/json') and then there is one for a particular user's activity ('activity/'. $user->uid .'/json').
'activity/all/json',
'callback' => 'activity_json',
'callback arguments' => array(ACTIVITY_ALL, 1),
'access' => user_access('view public activity'),
);
...
$items[] = array(
'path' => 'activity/'. $user->uid. '/json',
'callback' => 'activity_json',
'callback arguments' => array($user->uid, 1),
'type' => MENU_CALLBACK,
);
...
}
?>
These paths point to a function that pulls in the latest activity out of the {activity} table and then returns it to the page with a good ol' drupal_to_js().
uid, NULL, NULL, TRUE);
$feed_title = t('Activity for @username', array('@username' => theme('username', $user)));
}
}
if (count($activities) > 0) {
foreach ($activities as $activity) {
$message = activity_token_replace($activity);
$items .= ''. format_date($activity['created'], 'small') .' ';
$items .= ''. url('activity/'. $user->uid, NULL, NULL, TRUE) .' ';
$items .= ''. $message .' ';
}
}
drupal_set_header('Content-Type: application/x-javascript');
print drupal_to_js($items);
die();
}
?>
Now here's a nice little jQuery plug-in called spy.js that I thought would work perfectly for this. As it turns out... it did ;-)
I'd like to incorporate this as the default activity view, but need to get some feedback on it, which is the reason for this whole article in the first place. Until then, I stuck this on the theme layer.
' + json.date + ' ' + json.message + ' ';
// Prepend the HTML inside the container
$('table tbody').prepend(html);
}",
'inline');
return $table;
}
?>
Take a look at the issue here.
Tasks for Improving:
- convert viewsbookmarkactivity to new api - task
- convert votingapiactivity to new api - task
- upgrade path from 5.x.2
- this is currently about half done. check here.
- idea about the UI (build your choice of contrib's implementation)
- this is an idea I had the other night about creating a UI for activity that will allow anyone to implement a [module]activity of their own. Something like Views UI that will make so a user does not have to now how to write a definition/contrib module for activity, but hold it entirely in the database or a array definition. Needless to say I'll be studying a lot of merlinofchaos's code for this ;) I'll write more on this as it formulates in my brain.
Comments
Steve Madden (not verified)
Sun, 06/08/2008 - 13:59
Permalink
Thanks for Sharing
Appreciate you sharing these tips and the plugin.
Thanks
Steve
qectory (not verified)
Sun, 01/04/2009 - 05:49
Permalink
good
Very cool design! I find very interesting information at this article, thanks!
Pages