You are here

function fb_devel_info in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb_devel.module \fb_devel_info()
  2. 6.2 fb_devel.module \fb_devel_info()
1 string reference to 'fb_devel_info'
fb_devel_block_view in ./fb_devel.module

File

./fb_devel.module, line 567
Makes development with Drupal for Facebook much easier. Keep this module enabled until you're confident your app works perfectly.

Code

function fb_devel_info() {
  global $_fb, $_fb_app;
  global $user;
  global $base_url;
  global $base_path;
  $info = array();
  if ($_fb) {
    if (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_CANVAS) {
      $info['Page Status'] = t('Serving canvas page.');
    }
    elseif (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_CONNECT) {
      $info['Page Status'] = t('Connected via Facebook Connect');
    }
    elseif (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_PROFILE) {
      $info['Page Status'] = t('Serving deprecated FBML profile tab');
    }
    elseif (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_PAGE_TAB) {
      $info['Page Status'] = t('Iframe tab on page %page', array(
        '%page' => fb_settings(FB_SETTINGS_PAGE_ID),
      ));
    }
    elseif (!fb_settings(FB_SETTINGS_TYPE)) {
      $info['Page Status'] = t('Facebook PHP SDK initialized.');

      // Either a facebook connect page, or canvas page where user has not authorized app.
    }
    else {
      $info['Page Status'] = t('Global fb instance is set, but page type unknown (%type).', array(
        '%type' => fb_settings(FB_SETTINGS_TYPE),
      ));
    }
    $fbu = fb_facebook_user();
    $info['fb_facebook_user'] = $fbu;
    if (!$fbu) {
      $info['login button'] = theme('fb_login_button', array(
        'text' => 'Connect',
      ));
      $info['login link'] = "<a href=# onclick='FB.login(function(response) {alert(\"FB.login() success.\");}, {scope:Drupal.settings.fb.perms}); return false;'>fb login</a>";
    }

    // Tests for link on canvas pages (iframe cookie test)

    //$link_test = url(fb_scrub_urls(request_path()), array('absolute' => TRUE));

    //$info['link test'] = "<a href=\"$link_test\">link test (processed)</a>";

    //$info['link test 2'] = "<a href='$link_test'>link test (not processed)</a>";
    if ($fbu && FALSE) {

      // Disabled as this expensive check can cause problems.
      if (!fb_api_check_session($_fb)) {
        $info['fb_api_check_session()'] = t('Returned FALSE');
      }
      else {
        $info['fb_api_check_session()'] = t('Returned TRUE');
      }
    }
  }
  else {
    $info['Page Status'] = t('Not a canvas page.');
  }

  // Use theme_username() rather than theme('username') because we want link to local user, even when FBML is enabled
  if ($user->uid) {
    $name = $user->name;
  }
  else {
    $name = "anonymous";
  }
  $info['local user'] = theme_username(array(
    'account' => $user,
    'attributes_array' => array(),
    'name' => $name,
    'extra' => '',
  ));
  $info['fb_get_fbu'] = fb_get_fbu($user->uid);
  $info['base_url'] = $base_url;
  $info['base_path'] = $base_path;
  $info['url() returns'] = url();
  $info['current_path'] = current_path();
  $info['arg(0) is'] = arg(0);
  $info['arg(1) is'] = arg(1);
  $info['session_id'] = session_id();
  $info['session_name'] = session_name();
  $info['fb_settings()'] = fb_settings();
  $info['request'] = $_REQUEST;
  $info['user'] = $GLOBALS['user'];
  $info['fb_app'] = $_fb_app;
  if (isset($_SESSION)) {
    $info['session'] = $_SESSION;
  }
  $info['cookies'] = $_COOKIE;
  $info['cache'] = variable_get('cache', NULL);
  if ($_fb) {
    $info['signed_request'] = $_fb
      ->getSignedRequest();
    try {

      // app properties
      $token = fb_get_token($_fb);

      // @todo: getAppProperties deprecated.  Use graph API instead.
      $props = $_fb
        ->api(array(
        'method' => 'admin.getAppProperties',
        'properties' => 'about_url',
        'application_name',
        'access_token' => $token,
      ));
      $info['application properties'] = $props;
    } catch (FacebookApiException $e) {
      fb_log_exception($e, "failed to get app properties");
    }

    // $info["fb->getSession()"] = $_fb->getSession();
    $info["fb->getSignedRequest()"] = $_fb
      ->getSignedRequest();
    if ($fbu) {
      try {
        $params = array(
          'access_token' => fb_get_token($_fb, $fbu),
        );
        $info["fb->api({$fbu})"] = $_fb
          ->api($fbu, $params);
        $info["fb->api(/app)"] = $_fb
          ->api("/app", $params);
        $info["fb->api(/me/permissions)"] = $_fb
          ->api("/me/permissions", $params);
      } catch (FacebookApiException $e) {
        if (fb_verbose() == 'extreme') {

          // After oauth upgrade, this exception is thrown always, when using app token.
          // So only show error when fb_verbose is extreme.  Hopefully facebook will fix the issue.
          fb_log_exception($e, "failed to look up _fb->api({$fbu}).");

          // Dont show token, it can inlude app secret.  using token " . fb_get_token($_fb));
        }
      }
    }
  }
  $form = array();
  foreach ($info as $key => $val) {
    if (is_array($val) || is_object($val)) {
      $form[] = array(
        '#type' => 'fieldset',
        '#title' => t($key),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => count($form),
        'value' => array(
          '#prefix' => '',
          '#suffix' => '',
          '#type' => 'markup',
          '#markup' => dprint_r($val, 1),
        ),
      );
    }
    else {
      $form[$key] = array(
        '#markup' => t($key) . ' = ' . $val,
        '#weight' => count($form),
        '#suffix' => '<br/>',
      );
    }
  }
  return $form;
}