Index: fb.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fb/fb.module,v retrieving revision 1.49 diff -u -p -r1.49 fb.module --- fb.module 11 Jun 2009 18:00:24 -0000 1.49 +++ fb.module 24 Jul 2009 21:51:59 -0000 @@ -809,4 +809,99 @@ function fb_verbose() { return variable_get('fb_verbose', NULL); } +/** + * 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_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! + */ + +/** + * Define custom_url_rewrite_inbound() if the url_alter.module is not enabled. + */ +if (!function_exists('custom_url_rewrite_inbound')) { + function custom_url_rewrite_inbound(&$result, $path, $path_language) { + fb_url_alter_inbound($result, $path, $path_language); + } +} + +/** + * Implementation of hook_url_alter_outbound(). + */ +//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_url_alter_outbound(&$path, &$options, $original_path) { + //dpm(func_get_args(), 'fb_settings_url_rewrite_outbound'); + $pre = ''; + + // Prefix each known value to the URL + foreach (array_reverse(_fb_settings_url_rewrite_prefixes()) as $prefix) { + if ($value = fb_settings($prefix)) + $pre .= $prefix . '/'. $value . '/'; + } + $path = $pre . $path; + + return $path; +} + +/** + * Define custom_url_rewrite_outbound() if the url_alter.module is not enabled. + */ +if (!function_exists('custom_url_rewrite_outbound')) { + function custom_url_rewrite_outbound(&$path, &$options, $original_path) { + fb_url_alter_outbound($path, $options, $original_path); + } +} + +/** + * Implementation of hook_url_alter_inbound(). + * + * Rewrite URLs for facebook canvas pages. + * + * Ideally, this function would live in fb_canvas.module and only be + * set when serving canvas pages. However, it gets called before + * modules are loaded. So it must live here. + */ +function fb_url_alter_inbound(&$result, $path, $path_language){ + //$origpath = $path; + //watchdog('fb_settings', "fb_settings_url_rewrite_inbound($result, $path, $path_language)", array(), WATCHDOG_DEBUG); + + // 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], _fb_settings_url_rewrite_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; + } + 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 { //resolve aliases for non-fb-callbacks + $alias = drupal_lookup_path('source', $path, $path_language); + if ($alias) + $path = $alias; + } + + $result = $path; +} + ?> Index: fb_settings.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fb/fb_settings.inc,v retrieving revision 1.6 diff -u -p -r1.6 fb_settings.inc --- fb_settings.inc 5 Mar 2009 17:07:36 -0000 1.6 +++ fb_settings.inc 24 Jul 2009 21:51:59 -0000 @@ -47,94 +47,6 @@ if ($nid = _fb_settings_parse(FB_SETTING } -/** - * 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_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! - */ - -//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) { - 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) { - 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) { - //dpm(func_get_args(), 'fb_settings_url_rewrite_outbound'); - $pre = ''; - - // Prefix each known value to the URL - foreach (array_reverse(_fb_settings_url_rewrite_prefixes()) as $prefix) { - if ($value = fb_settings($prefix)) - $pre .= $prefix . '/'. $value . '/'; - } - $path = $pre . $path; - - return $path; -} - -/** - * Rewrite URLs for facebook canvas pages. - * - * Ideally, this function would live in fb_canvas.module and only be - * set when serving canvas pages. However, it gets called before - * modules are loaded. So it must live here. - */ -function fb_settings_url_rewrite_inbound(&$result, $path, $path_language){ - //$origpath = $path; - //watchdog('fb_settings', "fb_settings_url_rewrite_inbound($result, $path, $path_language)", array(), WATCHDOG_DEBUG); - - // 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], _fb_settings_url_rewrite_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; - } - 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 { //resolve aliases for non-fb-callbacks - $alias = drupal_lookup_path('source', $path, $path_language); - if ($alias) - $path = $alias; - } - - $result = $path; -} - function fb_settings($key, $value = NULL) { static $cache = array(); if (isset($value)) {