You are here

function fb_devel_info in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 6.2 fb_devel.module \fb_devel_info()
  2. 7.3 fb_devel.module \fb_devel_info()
1 string reference to 'fb_devel_info'
fb_devel_block in ./fb_devel.module
Implements hook_block().

File

./fb_devel.module, line 560
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', '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['q']), 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) {
      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
  $info['local user'] = theme_username($user);
  $info['fb_get_fbu'] = fb_get_fbu($user->uid);
  $info['base_url'] = $base_url;
  $info['base_path'] = $base_path;
  $info['url() returns'] = url();
  $info['$_REQUEST[q] is'] = isset($_REQUEST['q']) ? $_REQUEST['q'] : NULL;
  $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;
  $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 {
        $info["fb->api({$fbu})"] = $_fb
          ->api($fbu, array(
          'access_token' => fb_get_token($_fb),
        ));
      } 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_string($val) || is_numeric($val) || !$val) {
      $form[] = array(
        '#value' => t($key) . ' = ' . $val,
        '#weight' => count($form),
        '#suffix' => '<br/>',
      );
    }
    else {
      $form[] = array(
        '#type' => 'fieldset',
        '#title' => t($key),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => count($form),
        'value' => array(
          '#prefix' => '<pre>',
          '#suffix' => '</pre>',
          '#type' => 'markup',
          '#value' => dprint_r($val, 1),
        ),
      );
    }
  }

  // It's not really a form, but we like collapsible fieldsets
  return $form;
}