You are here

function fb_tab_added in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb_tab.module \fb_tab_added()

Drupal menu callback. User has added a tab to one of their pages.

1 string reference to 'fb_tab_added'
fb_tab_menu in ./fb_tab.module

File

./fb_tab.module, line 471
This module provides support for "Profile Tabs" that can be added to facebook pages (no longer allowed for user profiles).

Code

function fb_tab_added($fb_app) {

  //dpm($_REQUEST, __FUNCTION__); // debug what facebook has passed to us
  if (empty($_REQUEST['tabs_added'])) {

    // Sanity check.
    drupal_set_message(t('Failed to add tab to facebook page.'), 'error');
    return t('Failed to add tab to facebook page.');
  }
  foreach ($_REQUEST['tabs_added'] as $page_id => $added) {

    // TODO use batch graph api.
    $graph = fb_graph($page_id, array());
    watchdog('fb_tab', "Facebook application %label (%app_id) added to page %name (%page_id)", array(
      '%label' => $fb_app->label,
      '%app_id' => $fb_app->id,
      '%name' => $graph['name'],
      '%page_id' => $graph['id'],
    ));
  }

  // Redirect user to the page tab they've added.
  if ($graph['link']) {

    // This undocumented format seems to be the right URL for a page tab.
    $url = $graph['link'] . '?sk=app_' . $fb_app->id;
    drupal_goto($url);
  }

  // If drupal_goto succeeds, user will not see this.
  return t('Added application to Facebook page.');
}