Index: fb_infinite.info
===================================================================
--- fb_infinite.info	(revision 1.1)
+++ fb_infinite.info	(6.x working copy)
@@ -1,5 +1,7 @@
 name=Facebook Infinite Session
 description=Configure an infinite session that allows use of the Facebook API from non-canvas pages.  For example, to access Facebook API from a cron job.
 package = Facebook
-dependencies = fb
+dependencies[] = fb
+core = 6.x
 
+version = "6.x-1.x-dev"
Index: fb_infinite.module
===================================================================
--- fb_infinite.module	(revision 1.3)
+++ fb_infinite.module	(6.x working copy)
@@ -24,43 +24,58 @@
 /**
  * hook_menu
  */
-function fb_infinite_menu($may_cache) {
-  $items = array();
-  if ($may_cache) {
-    $items[] = array('path' => 'fb/infinite/display',
-                     'title' => t('Facebook session information'),
-                     'access' => user_access('administer fb apps'), // perm defined in fb_app.module
-                     'callback' => 'fb_infinite_display_page',
-                     'type' => MENU_CALLBACK,
+function fb_infinite_menu() {
+  $items['fb/infinite/display'] = array(
+      'title' => t('Facebook session information'),
+      'page callback' => 'fb_infinite_display_page',
+      'access callback' => 'user_access',
+      'access arguments' => array('administer fb apps'), // perm defined in fb_app.module
+      'type' => MENU_CALLBACK,
+  );
+  //TODO: not sure quite about this, hook_menu() is rarely called. non-cached hook_menu stuff belongs in hook_init() maybe instead now?
+  if ($node->type == 'fb_app') {
+    $items['node/%fb_infinite/fb/infinite/test'] = array(
+        'title' => 'Infinite session test',
+        'page callback' => 'fb_infinite_test_page',
+        'page arguments' => array(1),
+        'access callback' => 'node_access',
+        'access arguments' => array('update', 1),
+        'type' => MENU_LOCAL_TASK,
     );
   }
-  else {
-    if (arg(0) == 'node' && is_numeric(arg(1))) {
-      $node = node_load(arg(1));
-      if ($node->type == 'fb_app') {
-        // Only show if infinite session is configured.
-        $fb_app_data = fb_app_get_data($node->fb_app);
-        $fb_infinite_data = $fb_app_data['fb_infinite'];
-        if ($fb_infinite_data['key']) {
-          $items[] = array('path' => "node/$node->nid/fb/infinite/test",
-                           'title' => t('Infinite session test'),
-                           'type' => MENU_LOCAL_TASK,
-                           'access' => node_access('update', $node),
-                           'callback' => 'fb_infinite_test_page',
-                           'callback arguments' => array($node->nid),
-          );
-        }
-      }
-    }
-  }
   return $items;
 }
 
+
+/**
+ * Implementation of hook_load to create custom loader for hook_menu
+ * Checks a fb_app nid to see if infinite session is configured
+ *
+ * see "Defining your own wildcard loader" - http://drupal.org/node/209056
+ * passing $nid not needed if menu_get_object were to work
+ */
+function fb_infinite_load($nid) {
+  if (!is_numeric($nid)) {
+    return FALSE;
+  }
+  $node = node_load($nid);// menu_get_object;
+
+  if ($node->type == 'fb_app') {
+    // Only allow menu item if infinite session is configured.
+    $fb_app_data = fb_app_get_data($node->fb_app);
+    $fb_infinite_data = $fb_app_data['fb_infinite'];
+  }
+  if (!isset($fb_infinite_data['key'])) {
+    return FALSE;
+  }
+  return $node->nid;
+}
+
 /**
  * Implementation of hook_form_alter.
  */
-function fb_infinite_form_alter($form_id, &$form) {
-  //drupal_set_message("fb_infinte_form_alter($form_id) " . dpr($form, 1));
+function fb_infinite_form_alter(&$form, &$form_state, $form_id) {
+  //drupal_set_message("fb_infinite_form_alter($form_id) " . dpr($form, 1)) . dpr($form_state, 1));
   
   // Add our settings to the fb_app edit form.
   if (is_array($form['fb_app_data'])) {
@@ -117,7 +132,7 @@
 
 function fb_infinite_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   if ($node->type == 'fb_app') {
-    if ($op == 'submit') {
+    if ($op == 'presave') {
       $fb_app_data = $node->fb_app_data;
       $fb_infinite_data = $fb_app_data['fb_infinite'];
 
@@ -183,20 +198,19 @@
                                                  'status',
                                            ));
     $info = $info[0];
-    $fb_link = l($info['name'], 'http://www.facebook.com/profile.php', NULL, 'id='.$info['uid']);
+    $fb_link = l($info['name'], 'http://www.facebook.com/profile.php', array('query' => 'id='.$info['uid']));
     
-    drupal_set_message(t('Infinite session key is working.'));
+    drupal_set_message('Infinite session key is working.');
     $output .= '<p>'.t('Facebook infinite session user: !user',
                        array('!user' => $fb_link)) . '</p>';
     $output .= '<p>'.t('This page cannot test that the session key will never expire.  If your cron jobs start to fail, return here to test the login again.').'</p>';
     return $output;
   }
   else {
-    drupal_set_message(t('Infinite session key test failed.'), 'error');
+    drupal_set_message('Infinite session key test failed.', 'error');
     // TODO: provide helpful hints of how to fix the problem.
     $output .= '<p>'.t('Unable to log into Facebook using infinite session key.').'</p>';
   }
   return $output;
 }
 
-?>
\ No newline at end of file
