You are here

function fb_url_inbound_alter in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 6.2 fb_url_rewrite.inc \fb_url_inbound_alter()
  2. 7.4 fb.module \fb_url_inbound_alter()
  3. 7.3 fb_url_rewrite.inc \fb_url_inbound_alter()

Implementation of hook_url_inbound_alter().

Rewrite URLs for facebook canvas pages, and connect callbacks.

1 call to fb_url_inbound_alter()
fb_url_rewrite.inc in ./fb_url_rewrite.inc
Performs custom url rewriting for Drupal for Facebook.
2 string references to 'fb_url_inbound_alter'
fb_canvas_fb_admin in ./fb_canvas.admin.inc
Implementation of hook_fb_admin().
fb_tab_fb_admin in ./fb_tab.admin.inc
Implementation of hook_fb_admin().

File

./fb_url_rewrite.inc, line 134
Performs custom url rewriting for Drupal for Facebook.

Code

function fb_url_inbound_alter(&$result, $path, $path_language) {
  global $language;

  // Check language configuration mode.
  $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);

  //dpm(func_get_args(), 'fb_settings_url_rewrite_outbound'); // debug

  // See if this is a request for us.
  if (strpos($path, FB_SETTINGS_CB . '/') === 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);
      if (fb_settings($key) === NULL) {

        // defer to previously set values
        fb_settings($key, $value);
      }

      // Store for use later.
    }
    if (fb_settings(FB_SETTINGS_CB)) {

      // Check for language prefix.
      if (count($args) && ($mode == LANGUAGE_NEGOTIATION_PATH || $mode == LANGUAGE_NEGOTIATION_PATH_DEFAULT)) {

        // Get list of enabled languages.
        $languages = language_list('enabled');
        $languages = $languages[1];
        foreach ($languages as $lang) {
          if (!empty($lang->prefix) && $lang->prefix == $args[0]) {
            $prefix = array_shift($args);
            $path_language = $lang->language;
            $language = $lang;
            break;
          }
        }
      }
      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;
}