Index: favorite_nodes.info
===================================================================
--- favorite_nodes.info	(revision 4730)
+++ favorite_nodes.info	(revision 4737)
@@ -1,10 +1,5 @@
-; $Id: favorite_nodes.info,v 1.1.2.1 2007/06/18 23:06:42 dww Exp $
+; $Id$
 name = Favorite Nodes
 description = Allows users to manage a favorite list of nodes.
-package = 
-
-; Information added by drupal.org packaging script on 2008-03-14
-version = "5.x-1.2"
-project = "favorite_nodes"
-datestamp = "1205508608"
-
+package = Other
+core = 6.x
Index: README.txt
===================================================================
--- README.txt	(revision 4730)
+++ README.txt	(revision 4737)
@@ -1,4 +1,4 @@
-$Id: README.txt,v 1.4.2.1 2007/12/29 20:39:43 kbahey Exp $
+$Id$
 
 Copyright 2006 http://2bits.com
 
Index: favorite_nodes.module
===================================================================
--- favorite_nodes.module	(revision 4730)
+++ favorite_nodes.module	(revision 4737)
@@ -1,5 +1,5 @@
 <?php
-// $Id: favorite_nodes.module,v 1.5.2.7 2008/03/14 15:27:27 kbahey Exp $
+// $Id$
 
 define('FAVORITE_NODES_NODE_TYPE',       'favorite_nodes_node_type_');
 define('FAVORITE_NODES_PERM_ADD',        'create favorite nodes');
@@ -16,8 +16,8 @@
 /**
  * Implementation of hook_help().
  */
-function favorite_nodes_help($section) {
-  switch ($section) {
+function favorite_nodes_help($path, $arg) {
+  switch ($path) {
     case 'admin/help#favorite_nodes':
     case 'admin/modules#description':
       return t('Allows users to manage a favorite list of nodes.');
@@ -31,52 +31,59 @@
 /**
  * Implementation of hook_menu().
  */
-function favorite_nodes_menu($may_cache) {
+function favorite_nodes_menu() {
   global $user;
   $items = array();
 
-  if ($may_cache) {
-    $items[] = array(
-      'title'              => 'Favorite nodes',
-      'path'               => 'admin/settings/favorite_nodes',
-      'description'        => 'Settings for favorite nodes',
-      'callback'           => 'drupal_get_form',
-      'callback arguments' => 'favorite_nodes_settings',
+    $items['admin/settings/favorite_nodes'] = array(
+      'title'              => t('Favorite nodes'),
+      'description'        => t('Settings for favorite nodes'),
+      'page callback'           => 'drupal_get_form',
+      'page arguments' => array('favorite_nodes_settings'),
       'type'               => MENU_NORMAL_ITEM,
-      'access'             => user_access(FAVORITE_NODES_PERM_ADMINISTER),
+      'access arguments'   => array(FAVORITE_NODES_PERM_ADMINISTER),
     );
 
-    $items[] = array(
-      'path'     => 'favorite_nodes/add',
-      'callback' => 'favorite_nodes_add_page',
+    $items['favorite_nodes/add/%node'] = array(
+      'page callback' => 'favorite_nodes_add_page',
+      'page arguments' => array(2),
       'type'     => MENU_CALLBACK,
-      'access'   => user_access(FAVORITE_NODES_PERM_ADD),
+      'access arguments'   => array(FAVORITE_NODES_PERM_ADD),
     );
 
-    $items[] = array(
-      'path'     => 'favorite_nodes/delete',
-      'callback' => 'favorite_nodes_delete_page',
+    $items['favorite_nodes/delete/%node'] = array(
+      'page callback' => 'favorite_nodes_delete_page',
+      'page arguments' => array(2),
       'type'     => MENU_CALLBACK,
-      'access'   => user_access(FAVORITE_NODES_PERM_ADD),
+      'access arguments'   => array(FAVORITE_NODES_PERM_ADD),
     );
  
-    $items[] = array(
-      'path'     => 'favorite_nodes/view',
-      'callback' => 'favorite_nodes_view_page',
+    $items['favorite_nodes/view/%user/%favorite_nodes_nodetype'] = array(
+      'page callback' => 'favorite_nodes_view_page',
+      'page arguments' => array(2, 3),
       'title'    => t('Favorites'),
       'type'     => MENU_CALLBACK,
-      'access'   => user_access(FAVORITE_NODES_PERM_VIEW),
+      'access arguments'   => array(FAVORITE_NODES_PERM_VIEW),
     );
 
-    $items[] = array(
-      'path'     => 'favorites/view',
-      'callback' => 'favorite_nodes_view_page',
+    // This next bit doesn't seem to be *used*?
+    /*$items['favorites/view'] = array(
+      'page callback' => 'favorite_nodes_view_page',
+      //'page arguments' => array(2, 3),
       'type'     => MENU_CALLBACK,
-      'access'   => user_access(FAVORITE_NODES_PERM_VIEW),
+      'access arguments'   => array(FAVORITE_NODES_PERM_VIEW),
+    );*/
+    
+    // I really am not sure what this is here for...
+    $items['favorites/view/%user/%favorite_nodes_nodetype'] = array(
+      'title' => t('Favorite type'),
+      'page callback' => 'favorite_nodes_view_page',
+      'page arguments' => array(2, 3),
+      'type' => MENU_NORMAL_ITEM,
+      'access arguments' => array(FAVORITE_NODES_PERM_VIEW),
     );
-  }
-  else {
-    if ($user->uid && variable_get(FAVORITE_NODES_MENUS, 0)) {
+
+    /*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)) {
           $items[] = array(
@@ -88,12 +95,26 @@
           );
         }
       }
-    }
-  }
+    }*/
   return $items;
 }
 
 /**
+ * Checks that a nodetype is valid, so we can use %nodetype in our hook_menu paths.
+ *
+ * @param unknown_type $type
+ * @return unknown
+ */
+function favorite_nodes_nodetype_load($type) {
+  $node_types = _node_types_natcasesort();
+
+  if (!isset($node_types[$type]) || 0 == variable_get(FAVORITE_NODES_NODE_TYPE . $type, 0)) {
+    return FALSE;
+  }
+  return $type;
+}
+
+/**
  * Implementation of hook_xmlrpc().
  */
 function favorite_nodes_xmlrpc() {
@@ -107,6 +128,11 @@
   );
 }
 
+/**
+ * Returns a sorted array of node types, by name.
+ *
+ * @return unknown
+ */
 function _node_types_natcasesort() {
   static $node_types;
   
@@ -120,13 +146,13 @@
 /**
  * Implementation of hook_user().
  */
-function favorite_nodes_user($op, &$edit, &$user, $category = null) {
+function favorite_nodes_user($op, &$edit, &$account, $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);
+          $uid = intval($account->uid);
           $favorites = favorite_nodes_get($uid, $type->type, variable_get(FAVORITE_NODES_BLOCK_LIMIT, 5));
           $items = array();
           if (!empty($favorites)) {
@@ -135,16 +161,27 @@
             }
           }
           $fav_list[] = array(
-          'title' => l($type->name, "favorite_nodes/view/$user->uid/$type->type"),
-          'value' => theme('item_list', $items),
+            '#type' => 'user_profile_item',
+            '#title' => l($type->name, "favorite_nodes/view/$uid/$type->type"),
+            '#value' => theme('item_list', $items),
           );
         }
       }
-      return array(t('Favorites') => $fav_list);
+      if (!isset($account->content['favorites'])) {
+        $account->content['favorites'] = array();
+      }
+      $account->content['favorites'] += array(
+        '#type' => 'user_profile_category',
+        '#attributes' => array('class' => 'user-member'),
+        '#weight' => 5,
+        '#title' => t('Favorites'),
+      );
+      $account->content['favorites'] += $fav_list;
+      //return array(t('Favorites') => $fav_list);
       break;
 
     case 'delete':
-      favorite_nodes_delete_favorites($user->uid);
+      favorite_nodes_delete_favorites($account->uid);
       break;
   }
 }
@@ -194,7 +231,7 @@
             $count = db_result(db_query($sql, $type->type, $user->uid));
             if ($count > variable_get(FAVORITE_NODES_BLOCK_LIMIT, 5)) {
               $block['content'] .= "<div class=\"more\">\n";
-              $block['content'] .= l(t('More Favorite %types', array('%types' => variable_get(FAVORITE_NODES_BLOCK . $type->type, $type->name))), "favorite_nodes/view/$user->uid/$type->type");
+              $block['content'] .= l(t('More Favorite %types', array('%types' => variable_get(FAVORITE_NODES_BLOCK . $type->type, $type->name))), "favorite_nodes/view/$user->uid/$type->type", array('html' => TRUE));
               $block['content'] .= "</div>\n";
             }
           }
@@ -261,7 +298,7 @@
 /**
  * Implementation of hook_links().
  */
-function favorite_nodes_link($type, $node = null, $teaser = false) {
+function favorite_nodes_link($type, $node, $teaser = false) {
   global $user;
   $links = array();
   if ($type == 'node' && !$teaser) {
@@ -346,14 +383,14 @@
 /**
  * Add a favorite node.
  */
-function favorite_nodes_add($nid) {
+function favorite_nodes_add($node) {
   global $user;
 
-  $node = node_load($nid);
+  //$node = node_load($nid);
 
   if ($node->nid) {
-    db_query("DELETE FROM {favorite_nodes} WHERE nid = %d AND uid = %d", $nid, $user->uid);
-    db_query("INSERT INTO {favorite_nodes} (nid, uid, last) VALUES (%d, %d, %d)", $nid, $user->uid, time());
+    db_query("DELETE FROM {favorite_nodes} WHERE nid = %d AND uid = %d", $node->nid, $user->uid);
+    db_query("INSERT INTO {favorite_nodes} (nid, uid, last) VALUES (%d, %d, %d)", $node->nid, $user->uid, time());
 
     return true;
   }
@@ -365,10 +402,10 @@
 /**
  * Delete a favorite node.
  */
-function favorite_nodes_delete($nid) {
+function favorite_nodes_delete($node) {
   global $user;
    
-  db_query("DELETE FROM {favorite_nodes} WHERE nid = %d AND uid = %d", $nid, $user->uid);
+  db_query("DELETE FROM {favorite_nodes} WHERE nid = %d AND uid = %d", $node->nid, $user->uid);
 }
 
 /**
@@ -383,7 +420,8 @@
     $sql = "SELECT n.nid, n.title, f.uid, f.last FROM {node} n INNER JOIN {favorite_nodes} f ON n.nid = f.nid WHERE n.type = '%s' AND f.uid = %d ORDER by f.last DESC";
 
     $result = pager_query($sql, $limit, 0, null, $type, $uid);
-    if ($result && db_num_rows($result) > 0) {
+    //$result = db_query_range($sql, $type, $uid, 0, $limit);
+    if ($result) {
       while ($data = db_fetch_object($result)) {
         $row[$data->nid] = $data;
       }
@@ -395,30 +433,24 @@
 /**
  * Page to add a favorite node.
  */
-function favorite_nodes_add_page() {
-  $nid = arg(2);
-  if (is_numeric($nid)) {
-    $result = favorite_nodes_add($nid);
-    if ($result) {
-      drupal_set_message(t('The node was added to your favorites.'));
-    }
-    else {
+function favorite_nodes_add_page($node) {
+  $result = favorite_nodes_add($node);
+  if ($result) {
+    drupal_set_message(t('The node was added to your favorites.'));
+  }
+  else {
 
-    }
-    drupal_goto('node/'. $nid);
   }
-
-  drupal_not_found();
+  drupal_goto('node/'. $node->nid);
 }
 
 /**
  * Page to delete a favorite node.
  */
-function favorite_nodes_delete_page() {
+function favorite_nodes_delete_page($node) {
   global $user;
-  $nid = arg(2);
  
-  favorite_nodes_delete($nid);
+  favorite_nodes_delete($node);
   drupal_set_message(t('The node was deleted from your favorites'));
   drupal_goto("user/$user->uid");
 }
@@ -426,10 +458,13 @@
 /**
  * Page to display a user's favorite list.
  */
-function favorite_nodes_view_page() {
-  $uid  = arg(2);
-  $type = arg(3);
-  $output = theme('favorite_nodes_view_'. variable_get(FAVORITE_NODES_PAGE_TYPE, 'table'), favorite_nodes_get($uid, $type), $uid, $type);
+function favorite_nodes_view_page($user, $type = NULL) {
+  //$uid  = arg(2);
+  //$type = arg(3);
+  if ($type) {
+    drupal_set_title(t('Favorite @type', array('@type' => $type)));
+  }
+  $output = theme('favorite_nodes_view_'. variable_get(FAVORITE_NODES_PAGE_TYPE, 'table'), favorite_nodes_get($user->uid, $type), $user->uid, $type);
 
   print theme('page', $output);
 }
@@ -466,6 +501,22 @@
 }
 
 /**
+ * Implements hook_theme().
+ *
+ * @return unknown
+ */
+function favorite_nodes_theme() {
+  return array(
+    'favorite_nodes_view_teasers' => array(
+      'arguments' => array('list' => array(), 'uid' => NULL, 'type' => NULL),
+    ),
+    'favorite_nodes_view_table' => array(
+      'arguments' => array('list' => array(), 'uid' => NULL, 'type' => NULL),
+    ),
+  );
+}
+
+/**
  * TODO: This is not being used.. do we need it?
  */
 function theme_favorite_nodes_view_teasers($list = array(), $uid = null, $type = null) {
@@ -524,6 +575,8 @@
   return $output;
 }
 
+/*
+//TODO: Need to set to work with views.
 function favorite_nodes_views_tables() {
   $tables['favorite_nodes'] = array(
     'name' => 'favorite_nodes',
@@ -595,9 +648,9 @@
   $table = $query->get_table_name('favorite_nodes', $table_num);
   $query->set_distinct();
 
-  switch($filter['value']) {
+  switch ($filter['value']) {
     case 'uid_current':
-      if($user->uid) {
+      if ($user->uid) {
         $query->add_where("$table.uid = $user->uid");
       }
       break;
@@ -647,4 +700,5 @@
 function favorite_nodes_handler_user_count($fieldinfo, $fielddata, $value, $data) {
   return db_result(db_query("SELECT COUNT(*) FROM {favorite_nodes} WHERE nid = %d", $data->nid));
 }
+*/
 
Index: favorite_nodes.install
===================================================================
--- favorite_nodes.install	(revision 4730)
+++ favorite_nodes.install	(revision 4737)
@@ -1,31 +1,44 @@
 <?php
-// $Id: 
+// $Id$
 
+function favorite_nodes_schema() {
+  $schema = array();
+  $schema['favorite_nodes'] = array(
+    'description' => t("Table that holds user's favorite nodes."),
+    'fields' => array(
+      'nid' => array(
+        'description' => t('A favorite Node'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'uid' => array(
+        'description' => t('A user id'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'last' => array(
+        'description' => t(''),
+        'type' => 'int',
+      ),
+    ),
+    'primary key' => array('nid', 'uid'),
+  );
+  
+  return $schema;
+}
 /**
  * Implementation of hook_install().
  */
 function favorite_nodes_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $result = db_query("CREATE TABLE {favorite_nodes} (
-          nid     INT NOT NULL,
-          uid     INT NOT NULL,
-          last    INT,
-          PRIMARY KEY (nid, uid)
-          ) Type=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
-        ");
-      break;
-    case 'pgsql':
-      // TODO: need someone to do this on PostgreSQL
-      break;
-  }
+  drupal_install_schema('favorite_nodes');
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function favorite_nodes_uninstall() {
-  db_query('DROP TABLE {favorite_nodes}');
+  drupal_uninstall_schema('favorite_nodes');
   db_query("DELETE FROM {variable} WHERE name LIKE '%favorite_nodes%'");
 }
