? activity.patch
Index: activity.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/activity/activity.module,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 activity.module
--- activity.module	3 Dec 2007 17:40:47 -0000	1.1.2.2
+++ activity.module	3 Dec 2007 20:19:39 -0000
@@ -18,22 +18,32 @@
  */
 function activity_menu($may_cache) {
   $items = array();
+  global $user;
 
   if ($may_cache) {
     $items[] = array(
       'path' => 'activity',
-      'title' => t('activity'),
+      'title' => t('Activity'),
       'callback' => 'activity_page',
-      'callback arguments' => array(arg(1)),
       'access' => user_access('view activity'),
-      'type' => MENU_CALLBACK,
+      'weight' => 1,
     );
     $items[] = array(
-      'path' => 'activity/feed',
+      'path' => 'activity/all',
+      'title' => t('All activity'),
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+    );
+    $items[] = array(
+      'path' => 'activity/mine',
+      'title' => t('My activity'),
+      'access' => $user->uid,
+      'type' => MENU_LOCAL_TASK,
+    );
+    $items[] = array(
+      'path' => 'activity/all/feed',
+      'title' => t('All activity'),
       'callback' => 'activity_feed',
-      'callback arguments' => array(arg(2)),
-      'access' => user_access('view activity'),
-      'type' => MENU_CALLBACK,
+      'callback_arguments' => array('*'),
     );
     $items[] = array(
       'path' => 'admin/settings/activity',
@@ -59,6 +69,17 @@
       'type' => MENU_LOCAL_TASK,
     );
   }
+  else {
+    if ($user->uid) {
+      $items[] = array(
+        'path' => 'activity/'. $user->uid. '/feed',
+        'title' => t('My activity'),
+        'callback' => 'activity_feed',
+        'callback_arguments' => array($user->uid),
+        'type' => MENU_CALLBACK,
+      );
+    }
+  }
   return $items;
 }
 
@@ -187,7 +208,7 @@
   $aid = db_next_id('activity');
   db_query("INSERT INTO {activity} (aid, uid, module, type, action, tokens, timestamp) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", $aid, $uid, $module, $type, $action, serialize($tokens), time());
   return $aid;
-      }
+}
 
 function activity_get_activity($uids = NULL, $filters = NULL, $limit = NULL, $tablesort_headers = NULL) {
   // When $uids == *, it is a wildcard meaning return activities of all users.
@@ -200,10 +221,10 @@
     // The API supports passing in a single $uid. Wrap it in an array.
     if (!is_array($uids)) {
       $uids = array($uids);
-  }
+    }
     $wheres[] = "a.uid IN (%d)";
     $params[] = implode(',', $uids);
-}
+  }
 
   // Build sql limiting query to certain modules
   if (!empty($filters) && is_array($filters)) {
@@ -269,12 +290,12 @@
   elseif ($op == 'view') {
     switch ($delta) {
       case 'my':
-        $activities = activity_get_activity($user->uid);
+        $activities = activity_get_activity($user->uid, NULL, 5);
         return array('title' => t('My activity'),
           'content' => theme('activity_block', $activities));
 
       case 'all':
-        $activities =  activity_get_activity();
+        $activities =  activity_get_activity('*', NULL, 5);
         return array('title' => t('Recent activity'),
           'content' => theme('activity_block', $activities));
     }
@@ -283,13 +304,34 @@
 
 }
 
+function activity_page($page = 'all') {
+  global $user;
+  if ($page == 'mine') {
+    $activities = activity_get_activity(NULL, NULL, 20);
+    $table = activity_table($activities);
+    $feed_url =  url('activity/'. $user->uid. '/feed');
+    drupal_add_feed($feed_url);
+    $feed = theme('feed_icon', $feed_url);
+    return theme('activity_page', $activities, $table);
+  }
+  else if ($page == 'all') {
+    $activities = activity_get_activity('*', NULL, 20);
+    $table = activity_table($activities);
+    $feed_url =  url('activity/all/feed');
+    drupal_add_feed($feed_url);
+    $feed = theme('feed_icon', $feed_url);
+    return theme('activity_page', $activities, $table);
+  }
+}
 /**
  * Menu callback to display the records in a page
  */
-function activity_page($uid) {
-  $buddy_activity = activity_buddy_activity($uid);
-  arsort($buddy_activity);
-  $count = 0;
+function activity_table($activities) {
+  $headers = activity_get_tablesort_headers();
+  $output = theme('table', $headers, $activities);
+  $output .= theme('pager');
+  return $output;
+
   if (!empty($buddy_activity)) {
     foreach ($buddy_activity as $ba) {
       if ($count < variable_get('activity_message_limit', 20)) {
@@ -308,61 +350,53 @@
 }
 
 /**
- * theme function for displaying the users activity page
- */
-function theme_activity_page($items) {
-  return theme('item_list', $items, NULL, 'ul', array('class' => 'activity-list'));
-}
-
-/**
- * theme function for displaying the users activity page
- */
-function theme_activity_block($items) {
-  $activites = array();
-  foreach ($items as $activity) {
-    $activities[] = activity_token_replace($activity);
-  }
-  return theme('item_list', $activities, NULL, 'ul', array('class' => 'activity-list'));
-}
-
-/**
  * menu callback to return a feed of a signed in user's activity page
  */
-function activity_feed($user_name) {
-  $account = user_load(array('name' => $user_name));
-  $buddy_activity = activity_buddy_activity($account->uid);
-  drupal_set_header('Content-Type: text/xml; charset=utf-8');
-  print theme('activity_feed', $buddy_activity);
-  exit;
-}
+function activity_feed($arg) {
+  global $locale;
+  if (is_numeric($arg)) {
+    $user = user_load(array('uid' => $arg));
+    if ($user) {
+      $activities = activity_get_activity(NULL, NULL, 20);
+      $url =  url('activity/'. $user->uid);
+      $feed_title = t('Activity for @username', array('@username' => theme('username', $user)));
+    }
+  }
+  else if ($arg == 'all') {
+    $activities = activity_get_activity('*', NULL, 20);
+    $url =  url('activity/all');
+    $feed_title = t('All activity');
+  }
+
+  if (count($activities) > 0) {
+    foreach ($activities as $activity) {
+      $function = $activity['module']. '_format_rss_item';
+      if (function_exists($function)) {
+        // each module gets a chance to build its own feed item.
+        // They should use the $activity to prepare variables and
+        // call format_rss_item($title, $link, $item_text, $extra);
+        $items .= $function($activity);
+      }
+    }
+  }
 
-function theme_activity_feed($buddy_activity) {
-  global $base_url;
   $channel = array(
     'version'     => '2.0',
-    'title'       => variable_get('site_name', 'drupal') .' - '. variable_get('site_slogan', ''),
-    'link'        => $base_url,
+    'title'       => variable_get('site_name', 'Drupal') .' - '. $feed_title,
+    'link'        => $url,
     'description' => variable_get('site_mission', ''),
-    'language'    => $GLOBALS['locale'],
+    'language'    => $locale
   );
 
-  arsort($buddy_activity);
-  if (!empty($buddy_activity)) {
-    foreach ($buddy_activity as $ba) {
-      $item_title = $ba->module;
-      $item_tokens = unserialize($ba->tokens);
-      $link = l($item_tokens['node-title'], 'node/'. $item_tokens['node-id']);
-      $item_text = activity_token_replace($ba);
-      $items .= format_rss_item($item->title, $link, $item_text);
-    }
-  }
-
+  // TODO: Figure out what the right namespace should be.
+  $namespaces = array('xmlns:dc="http://purl.org/dc/elements/1.1/"');
   $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
-  $output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\">\n";
+  $output .= "<rss version=\"". $channel["version"] ."\" xml:base=\"". $base_url ."\" ". implode(' ', $namespaces) .">\n";
   $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
   $output .= "</rss>\n";
 
-  return $output;
+  drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
+  print $output;
 }
 
 /**
@@ -438,3 +472,23 @@
   $tests = file_scan_directory($dir, '\.test$');
   return array_keys($tests);
 }
+
+
+/**
+ * theme function for displaying the users activity page
+ */
+function theme_activity_page($activities, $table) {
+  return $table;
+  //return theme('item_list', $items, NULL, 'ul', array('class' => 'activity-list'));
+}
+
+/**
+ * theme function for displaying the users activity page
+ */
+function theme_activity_block($items) {
+  $activites = array();
+  foreach ($items as $activity) {
+    $activities[] = activity_token_replace($activity);
+  }
+  return theme('item_list', $activities, NULL, 'ul', array('class' => 'activity-list'));
+}
