--- favorite_nodes.module.orig	2008-07-20 22:51:33.000000000 +0200
+++ favorite_nodes.module	2008-07-20 22:49:55.000000000 +0200
@@ -13,6 +13,10 @@
 define('FAVORITE_NODES_PAGE_TYPE',       'favorite_nodes_page_type');
 define('FAVORITE_NODES_MENUS',           'favorite_nodes_menu');
 
+// View favorites in user info or in a menu_local_task of user page ?
+define('FAVORITE_NODES_VIEW_IN_PROFILE',  'favorite_nodes_view_in_profile');
+define('FAVORITE_NODES_VIEW_IN_LOCAL_TASK','favorite_nodes_view_in_local_task');
+
 /**
  * Implementation of hook_help().
  */
@@ -32,7 +36,6 @@
  * Implementation of hook_menu().
  */
 function favorite_nodes_menu($may_cache) {
-  global $user;
   $items = array();
 
   if ($may_cache) {
@@ -59,7 +62,7 @@
       'type'     => MENU_CALLBACK,
       'access'   => user_access(FAVORITE_NODES_PERM_ADD),
     );
- 
+
     $items[] = array(
       'path'     => 'favorite_nodes/view',
       'callback' => 'favorite_nodes_view_page',
@@ -76,6 +79,7 @@
     );
   }
   else {
+    global $user;
     if ($user->uid && variable_get(FAVORITE_NODES_MENUS, 0)) {
       foreach (_node_types_natcasesort() as $type) {
         if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {
@@ -89,6 +93,17 @@
         }
       }
     }
+    if (variable_get(FAVORITE_NODES_VIEW_IN_LOCAL_TASK, NULL) && user_access(FAVORITE_NODES_PERM_VIEW)) {
+      // arg(1) is always uid in user's profile page
+      $items[] = array(
+        'path'               => 'user/'.arg(1).'/favorites',
+        'title'              => t('Favorites'),
+        'callback'           => 'favorite_nodes_view_all_page',
+        'callback arguments' => array(arg(1)),
+        'type'               => MENU_LOCAL_TASK,
+        'access'             => user_access(FAVORITE_NODES_PERM_VIEW),
+      );
+    }
   }
   return $items;
 }
@@ -109,7 +124,7 @@
 
 function _node_types_natcasesort() {
   static $node_types;
-  
+
   if (!isset($node_types)) {
     $node_types = node_get_types();
     uasort($node_types, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);'));
@@ -123,24 +138,26 @@
 function favorite_nodes_user($op, &$edit, &$user, $category = null) {
   switch ($op) {
     case 'view':
-      $fav_list = array();
-      foreach (_node_types_natcasesort() as $type) {
-        if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {
-          $uid = intval($user->uid);
-          $favorites = favorite_nodes_get($uid, $type->type, variable_get(FAVORITE_NODES_BLOCK_LIMIT, 5));
-          $items = array();
-          if (!empty($favorites)) {
-            foreach ($favorites as $favorite) {
-              $items[] = l($favorite->title, "node/$favorite->nid");
+      if (variable_get(FAVORITE_NODES_VIEW_IN_PROFILE, 1)) {
+        $fav_list = array();
+        foreach (_node_types_natcasesort() as $type) {
+          if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {
+            $uid = intval($user->uid);
+            $favorites = favorite_nodes_get($uid, $type->type, variable_get(FAVORITE_NODES_BLOCK_LIMIT, 5));
+            $items = array();
+            if (!empty($favorites)) {
+              foreach ($favorites as $favorite) {
+                $items[] = l($favorite->title, "node/$favorite->nid");
+              }
             }
+            $fav_list[] = array(
+              'title' => l($type->name, "favorite_nodes/view/$user->uid/$type->type"),
+              'value' => theme('item_list', $items),
+            );
           }
-          $fav_list[] = array(
-          'title' => l($type->name, "favorite_nodes/view/$user->uid/$type->type"),
-          'value' => theme('item_list', $items),
-          );
         }
+        return array(t('Favorites') => $fav_list);
       }
-      return array(t('Favorites') => $fav_list);
       break;
 
     case 'delete':
@@ -168,7 +185,7 @@
   global $user;
 
   $node_types = _node_types_natcasesort();
-  
+
   switch ($op) {
     case 'list':
       return array(array('info' => t('Favorite nodes')));
@@ -305,6 +322,18 @@
     '#default_value' => variable_get(FAVORITE_NODES_PROFILE_LIMIT, 3),
     '#description' => t('How many items per type to display on the profile page.'),
   );
+  $form[$set][FAVORITE_NODES_VIEW_IN_PROFILE] = array(
+    '#type' => 'checkbox',
+    '#title' => t('View favorite nodes in profile informations'),
+    '#default_value' => variable_get(FAVORITE_NODES_VIEW_IN_PROFILE, 1),
+    '#description' => t('If you select this option, favorite nodes will be displayed into the user profile informations. This is the default behavior.'),
+  );
+  $form[$set][FAVORITE_NODES_VIEW_IN_LOCAL_TASK] = array(
+    '#type' => 'checkbox',
+    '#title' => t('View favorite nodes in a tab in user profile'),
+    '#default_value' => variable_get(FAVORITE_NODES_VIEW_IN_LOCAL_TASK, 0),
+    '#description' => t('If you select this option, a new tab in users page will be added. Note that you can cumulate this option with the previous one, but you may choose one of the two.'),
+  );
   $form[$set][FAVORITE_NODES_PAGE_TYPE] = array(
     '#type' => 'select',
     '#title' => t('Type of Page Display for Favorite Nodes'),
@@ -367,7 +396,7 @@
  */
 function favorite_nodes_delete($nid) {
   global $user;
-   
+
   db_query("DELETE FROM {favorite_nodes} WHERE nid = %d AND uid = %d", $nid, $user->uid);
 }
 
@@ -417,18 +446,37 @@
 function favorite_nodes_delete_page() {
   global $user;
   $nid = arg(2);
- 
+
   favorite_nodes_delete($nid);
   drupal_set_message(t('The node was deleted from your favorites'));
   drupal_goto("user/$user->uid");
 }
 
+/*
+ * Page to display all user's favorite list.
+ */
+function favorite_nodes_view_all_page($uid) {
+  $output = "";
+
+  if (($uid = intval($uid)) > 0) {
+    $fav_list = array();
+    foreach (_node_types_natcasesort() as $type) {
+      if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {
+        $favorites = favorite_nodes_get($uid, $type->type, variable_get(FAVORITE_NODES_BLOCK_LIMIT, 5));
+        $output .= theme('favorite_nodes_view_'. variable_get(FAVORITE_NODES_PAGE_TYPE, 'table'), $favorites, $uid, $type->type);
+      }
+    }
+  }
+
+  return $output;
+}
+
 /**
  * Page to display a user's favorite list.
  */
 function favorite_nodes_view_page() {
-  $uid  = arg(2);
   $type = arg(3);
+  $uid  = arg(2);
   $output = theme('favorite_nodes_view_'. variable_get(FAVORITE_NODES_PAGE_TYPE, 'table'), favorite_nodes_get($uid, $type), $uid, $type);
 
   print theme('page', $output);
@@ -467,6 +515,7 @@
 
 /**
  * TODO: This is not being used.. do we need it?
+ * Notice: we should, 'teaser' view is a good feature.
  */
 function theme_favorite_nodes_view_teasers($list = array(), $uid = null, $type = null) {
   $type_desc = variable_get(FAVORITE_NODES_BLOCK . $type, $type);
@@ -497,9 +546,13 @@
  * Table which displays favorite node lists.
  */
 function theme_favorite_nodes_view_table($list = array(), $uid = null, $type = null) {
-  global $user;
+  if (! $uid) {
+    global $user;
+  }
+  else {
+    $user = user_load(array('uid' => $uid));
+  }
 
-  $account = user_load(array('uid' => $uid));
   $header = array(t('Title'), t('Added'), t('Operations'));
 
   $rows = array();
@@ -520,7 +573,7 @@
   $output .= '<h2>'. t('Favorite !types for !user', array('!type' => variable_get(FAVORITE_NODES_BLOCK . $type, node_get_types('name', $type)), '!user' => theme('username', $account))) ."</h2>\n";
   $output .= theme('table', $header, $rows);
   $output .= theme('pager');
-  
+
   return $output;
 }
 
