You are here

function fb_canvas_url_outbound_alter in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb_canvas.module \fb_canvas_url_outbound_alter()
  2. 6.2 fb_canvas.module \fb_canvas_url_outbound_alter()
  3. 7.4 fb_canvas.module \fb_canvas_url_outbound_alter()

Implements hook_url_outbound_alter().

Parameters

$options: If $options['fb_canvas'] == TRUE, create an absolute URL to a canvas page. The URL will begin http://apps.facebook.com/... Also if $options['fb_canvas'] is an application label the url will link to that particular application.

1 call to fb_canvas_url_outbound_alter()
fb_url_outbound_alter in ./fb_url_rewrite.inc
Implements hook_url_outbound_alter().
1 string reference to 'fb_canvas_url_outbound_alter'
fb_url_outbound_alter in ./fb_url_rewrite.inc
Implements hook_url_outbound_alter().

File

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

Code

function fb_canvas_url_outbound_alter(&$path, &$options, $original_path) {

  // use $options['fb_url_alter'] = FALSE to suppress any alteration.
  if (isset($options['external']) && $options['external'] || isset($options['fb_url_alter']) && $options['fb_url_alter'] === FALSE) {
    return;
  }
  if (isset($options['fb_canvas']) && is_string($options['fb_canvas'])) {
    $fb_app = fb_get_app(array(
      'label' => $options['fb_canvas'],
    ));
  }
  else {
    $fb_app = isset($GLOBALS['_fb_app']) ? $GLOBALS['_fb_app'] : NULL;
  }
  if ($fb_app && isset($fb_app->canvas)) {
    if (isset($options['fb_canvas']) && $options['fb_canvas']) {

      // Make a url starting with apps.facebook.com/...
      $options[FB_SETTINGS_CB] = FALSE;

      // prevent fb_url_rewrite.inc from inserting 'fb_cb'.
      $options['absolute'] = TRUE;
      $options['base_url'] = fb_protocol() . "://apps.facebook.com/{$fb_app->canvas}";
    }
    if (fb_canvas_is_iframe()) {
      if (empty($options['absolute'])) {

        // Could append session param to internal links.  But for now we rely on fb_process().
      }
      else {

        //dpm($options, "fb_canvas_url_outbound_alter($path)");
      }

      // Drupal has a habit of adding ?destination=... to some URLs.
      // And Facebook for no good reason screws up when you do that.
      if (!empty($options['query'])) {
        $options['query'] = str_replace('destination=', 'fb_canvas_destination=', $options['query']);
      }
    }
  }
}