You are here

function fb_canvas_fix_url in Drupal for Facebook 6.2

Same name and namespace in other branches
  1. 5.2 fb_canvas.module \fb_canvas_fix_url()
  2. 5 fb_canvas.module \fb_canvas_fix_url()
  3. 6.3 fb_canvas.module \fb_canvas_fix_url()

Convert a local fully qualified path to a facebook app path. This needs to be used internally, to fix drupal_gotos upon form submission. Third party modules should not need to call this.

2 calls to fb_canvas_fix_url()
fb_canvas_fb in ./fb_canvas.module
Implementation of hook_fb().
fb_canvas_goto in ./fb_canvas.module
Uses $_fb->redirect on canvas pages, otherwise drupal_goto.

File

./fb_canvas.module, line 636
This module provides support for Canvas page applications. Use Drupal to power traditional Facebook Apps.

Code

function fb_canvas_fix_url($url, $fb_app) {

  //dpm(debug_backtrace(), "fb_canvas_fix_url($url)");
  global $base_url;

  // Url rewrites still used for iframe excursions.
  $patterns[] = "|{$base_url}/" . FB_SETTINGS_CB . "/{$fb_app->label}/|";

  // Here we hard-wire apps.facebook.com.  Is there an API to get that?
  $replacements[] = "http://apps.facebook.com/{$fb_app->canvas}/";

  // Page type helps themes support multiple iframes.
  $patterns[] = "|" . FB_SETTINGS_CB_TYPE . "/[^/]*/|";
  $replacements[] = "";
  $patterns[] = "|" . FB_SETTINGS_CB_SESSION . "/[^/]*/|";
  $replacements[] = "";

  // Fully qualified paths.
  $patterns[] = "|" . url('', array(
    'absolute' => TRUE,
  )) . "|";
  $replacements[] = "http://apps.facebook.com/{$fb_app->canvas}/";

  // Facebook will prepend "appNNN_" all our ids
  $patterns[] = "|#([^\\?]*)|";
  $replacements[] = "#app{$fb_app->id}_\$1";
  $url = preg_replace($patterns, $replacements, $url);
  return $url;
}