You are here

function fb_infinite_test_page in Drupal for Facebook 5.2

Same name and namespace in other branches
  1. 5 fb_infinite.module \fb_infinite_test_page()

Menu callback to test infinite session values.

1 string reference to 'fb_infinite_test_page'
fb_infinite_menu in ./fb_infinite.module
hook_menu

File

./fb_infinite.module, line 172
This module manages an infinite session for each Facebook App. http://wiki.developers.facebook.com/index.php/Infinite_session_keys

Code

function fb_infinite_test_page($nid) {
  if ($GLOBALS['fb']) {
    $url = $GLOBALS['fb_old_base_url'] . "?q=" . $_GET['q'];
    return t('Do not use this page from a canvas page.  Try !link.', array(
      '!link' => l($url, $url),
    ));
  }
  $fb_app = fb_get_app(array(
    'nid' => $nid,
  ));
  $fb = fb_api_init($fb_app, FB_FBU_INFINITE_SESSION);
  if ($fb) {
    $fbu = $fb->api_client
      ->users_getLoggedInUser();
    if ($fbu) {
      $info = $fb->api_client
        ->users_getInfo(array(
        $fbu,
      ), array(
        'about_me',
        'affiliations',
        'name',
        'is_app_user',
        'pic_big',
        'profile_update_time',
        'status',
      ));
      $info = $info[0];
      $fb_link = l($info['name'], 'http://www.facebook.com/profile.php', NULL, 'id=' . $info['uid']);
      drupal_set_message(t('Infinite session key is working.'));
      $output .= '<p>' . t('Facebook infinite session user: !user', array(
        '!user' => $fb_link,
      )) . '</p>';
      $output .= '<p>' . t('This page cannot test that the session key will never expire.  If your cron jobs start to fail, return here to test the login again.') . '</p>';
      return $output;
    }
    else {
      drupal_set_message(t('Infinite session key test failed.'), 'error');

      // TODO: provide helpful hints of how to fix the problem.
      $output .= '<p>' . t('Unable to log into Facebook using infinite session key.') . '</p>';
    }
  }
  else {
    drupal_set_message(t('Infinite session key test failed.'), 'error');
    $output .= '<p>' . t('Unable to log initialize Facebook API.') . '</p>';
  }
  return $output;
}