function fb_url_inbound_alter in Drupal for Facebook 7.4
Same name and namespace in other branches
- 6.3 fb_url_rewrite.inc \fb_url_inbound_alter()
- 6.2 fb_url_rewrite.inc \fb_url_inbound_alter()
- 7.3 fb_url_rewrite.inc \fb_url_inbound_alter()
Implements hook_url_inbound_alter().
Rewrite URLs for facebook canvas pages and page tabs. This is written in a generic way, so it will work with paths starting fb__canvas/... or fb__page/...
File
- ./
fb.module, line 1752
Code
function fb_url_inbound_alter(&$path, $original_path, $path_language) {
//dpm(func_get_args(), __FUNCTION__);
// Requests starting with 'fb__' are prefixed with name/value pairs.
// These should already have been parsed by fb_settings.inc, however we must remove them from the path.
if (strpos($path, 'fb__') === 0) {
$fb_url_alter_prefix =& drupal_static('fb_url_alter_prefix');
$fb_url_alter_prefix = '';
$fb_settings =& drupal_static('fb_settings');
$args = explode('/', $path);
while (!empty($args) && isset($fb_settings[$args[0]])) {
$key = array_shift($args);
$value = array_shift($args);
// What we pull off the path here must be prepended in outbound alter.
$fb_url_alter_prefix .= "{$key}/{$value}/";
// We could do something with the values here, but they've already been parsed into $fb_settings.
}
if (count($args)) {
$path = implode('/', $args);
// remaining args
}
else {
// frontpage
$path = variable_get('site_frontpage', 'node');
}
// Do we really have to do this here? It seems Drupal should do this only after all inbound alters complete!
$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;
}
$result = $path;
}
else {
// Not prefixed with fb__, nothing to do.
}
}