Index: fb_session.inc
===================================================================
--- fb_session.inc	(revision 1.1)
+++ fb_session.inc	(6.x working copy)
@@ -24,4 +24,4 @@
 
 // Important: edit the path where includes/session.inc is included so
 // that it works for your system.
-require_once('includes/session.inc');
\ No newline at end of file
+require_once('./includes/session.inc');
\ No newline at end of file
Index: fb_settings.inc
===================================================================
--- fb_settings.inc	(revision 1.1)
+++ fb_settings.inc	(6.x working copy)
@@ -4,6 +4,7 @@
 define('FB_SETTINGS_APP_NID', 'fb_cb');
 define('FB_SETTINGS_PAGE_TYPE', 'fb_cb_type');
 
+// NOTE: can't use variable_set() -- database.inc hasn't loaded yet, so db_query() in variable_set() fails
 if (!is_array($conf))
   $conf = array();
 
@@ -44,20 +45,51 @@
 }
 
 /**
- * Implementation of conf_url_rewrite
+ * Implementation of conf_url_rewrite_inbound
  * 
  * Defines the URL rewrite if not defined already.  If it is defined already,
- * or your using 118n modules, you should define a custom_url_rewrite in
- * settings.php which calls fb_canvas_url_rewrite in addition to any others
+ * or your using 118n modules, you should define a custom_url_rewrite_inbound in
+ * settings.php which calls fb_canvas_url_rewrite_inbound in addition to any others
  * that need to be called.  The order will be important!
  */
 
-if(!function_exists('custom_url_rewrite')) {
-  function custom_url_rewrite($type, $path, $original) {
-    return fb_settings_url_rewrite($type, $path, $original);
+//TODO: this needs confirmation.
+//custom_url_rewrite was dropped in 6.x so I split the 'source' portion of the old function
+//into _inbound and the 'alias' portion into _outbound versions
+//really guessing here, but it seems to be working
+if(!function_exists('custom_url_rewrite_inbound')) {
+  function custom_url_rewrite_inbound(&$result, $path, $path_language) {
+    $result = fb_settings_url_rewrite_inbound($result, $path, $path_language);
   }
 }  
 
+if(!function_exists('custom_url_rewrite_outbound')) {
+  function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
+    $path = fb_settings_url_rewrite_outbound($path, $options, $original_path);
+  }
+}  
+
+//TODO: especially verify this one - not sure what to do with Absolute paths, if anything
+//TODO: problem with _fb_canvas_make_form_action_local - is it caused by this?
+//TODO: I don't think the fb_canvas_is_fbml() and fb_canvas_is_iframe() functions are returning the right values either
+function fb_settings_url_rewrite_outbound($path, $options, $original_path) {
+  if (function_exists('fb_canvas_is_fbml')) {
+    global $fb_app;
+    if (fb_canvas_is_iframe()) {
+      //TODO: do something else?
+      $path  = $fb_app->canvas .'/'. $path;
+    }
+    else if (fb_canvas_is_fbml()) {
+      //if (!$options['absolute'])
+        //something
+      //else 
+	      $path  = $fb_app->canvas .'/'. $path;
+      //
+    }
+    //var_dump(array($path => $options));
+  }
+  return $path;
+}
 
 /**
  * Rewrite URLs for facebook canvas pages.
@@ -66,52 +98,44 @@
  * set when serving canvas pages.  However, it gets called before
  * modules are loaded.  So it must live here.
  */
-function fb_settings_url_rewrite($type, $path, $original){
-  //dpm(func_get_args(), 'fb_canvas_url_rewrite');
+function fb_settings_url_rewrite_inbound($result, $path, $path_language){
+  //$origpath = $path;
+  //dpm(func_get_args(), 'fb_canvas_url_rewrite_inbound');
   $prefixes = array(FB_SETTINGS_APP_NID, FB_SETTINGS_PAGE_TYPE);
-  if ($type == 'source') {
-    // See if this is a request for us.
-    if (strpos($path, FB_SETTINGS_APP_NID . '/') === 0) {
+  
+  // See if this is a request for us.
+  if (strpos($path, FB_SETTINGS_APP_NID . '/') === 0) {
 	  // Too soon for arg() function.
-      $args = explode('/', $path);
-      while (count($args) && in_array($args[0], $prefixes)) {
-        $key = array_shift($args);
-        $value = array_shift($args);
-        fb_settings($key, $value); // Store for use later.
+    $args = explode('/', $path);
+    while (count($args) && in_array($args[0], $prefixes)) {
+      $key = array_shift($args);
+      $value = array_shift($args);
+      $app_nid = fb_settings($key, $value); // Store for use later.
+    }
+    if ($app_nid = fb_settings(FB_SETTINGS_APP_NID)) {
+      if (count($args)) {
+        $path = implode('/', $args); // remaining args
+        $alias = drupal_lookup_path('source', $path, $path_language); //can't use drupal_get_normal_path, it calls custom_url_rewrite_inbound
+        if ($alias) 
+          $path = $alias;
       }
-      if ($app_nid = fb_settings(FB_SETTINGS_APP_NID)) {
-        if (count($args)) {
-          $path = implode('/', $args); // remaining args
-          $path = drupal_get_normal_path($path);
-        }
-        else
-          // frontpage
-          $path = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
+      else {
+        // frontpage
+        $path = variable_get('site_frontpage', 'node');
+        $alias = drupal_lookup_path('source', $path, $path_language);
+        if ($alias) 
+          $path = $alias;
+        $_REQUEST['destination'] = $path; //required workaround for compatibility with Global Redirect module, best practice?
       }
-    } 
+    }
   }
-  else if ($type == 'alias') {
-	if (function_exists('fb_canvas_is_fbml')) {
-	  $pre = '';
-	  if (fb_canvas_is_iframe()) {
-		// Rewrite for iframes
-		foreach ($prefixes as $prefix)
-		  if ($value = fb_settings($prefix))
-			$pre .= $prefix . '/'. fb_settings($prefix) . '/';
-		$path  = $pre . $path;
-	  }
-	  else if (fb_canvas_is_fbml()) {
-		// Rewrite for FBML
-		//$path = $fb_app->canvas . '/' . $path; // old way
-		// For now, same as for iframes, but may be different one day
-		foreach ($prefixes as $prefix)
-		  if ($value = fb_settings($prefix))
-			$pre .= $prefix . '/'. fb_settings($prefix) . '/';
-		$path  = $pre . $path;
-	  }
-	}
+  else { //resolve aliases for non-fb-callbacks
+    $alias = drupal_lookup_path('source', $path, $path_language);
+    if ($alias) 
+      $path = $alias;
   }
-  return $path;  
+  //print_r(array($origpath => $path));
+  return $path; //becomes $result after returned  
 }
 
 function fb_settings($key, $value = NULL) {
@@ -127,14 +151,12 @@
  */
 function _fb_settings_parse_nid() {
   if (isset($_GET['q'])) {
-	$path = $_GET['q'];
-	if (strpos($path, FB_SETTINGS_APP_NID . '/') === 0) {
-	  // Too soon for arg() function.
-	  $args = explode('/', $path);
-	  return $args[1];
-	}
+	  $path = $_GET['q'];
+	  if (strpos($path, FB_SETTINGS_APP_NID . '/') === 0) {
+	    // Too soon for arg() function.
+	    $args = explode('/', $path);
+	    return $args[1];
+	  }
   }
 }
 
-
-?>
\ No newline at end of file
