You are here

fb_devel.module in Drupal for Facebook 5.2

File

fb_devel.module
View source
<?php

function fb_devel_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'fb/devel',
      'callback' => 'fb_devel_page',
      'type' => MENU_CALLBACK,
      'access' => TRUE,
    );
    $items[] = array(
      'path' => 'fb/devel/fbu',
      'callback' => 'fb_devel_fbu_page',
      'type' => MENU_CALLBACK,
      'access' => TRUE,
    );
  }
  return $items;
}
function fb_devel_fb($op, $data, &$return) {
  $fb_app = $data['fb_app'];
  $fb = $data['fb'];
  if ($op == FB_OP_INITIALIZE) {

    // Sanity checks for canvas pages.
    $nid = fb_settings(FB_SETTINGS_APP_NID);
    if ($nid) {

      // We're in a canvas page callback, either FBML or iframe
      if ($nid != $fb_app->nid) {
        $message = t('fb_app id (%fb_app_id) does not equal fb settings id (%fb_settings_id).  This is usually caused by the wrong callback url on your <a href="!url">facebook application settings form</a>.', array(
          '%fb_app_id' => $fb_app->nid,
          '%fb_settings_id' => $nid,
          '!url' => "http://www.facebook.com/developers/apps.php",
        ));
        drupal_set_message($message, 'error');
        watchdog('fb_devel', $message);
      }

      // Theme sanity check
      global $theme;

      // for debug message
      if (isset($theme)) {
        $message = t('Drupal for Facebook is unable to override the theme settings.  This is usually because some module causes theme_init() to be invoked before fb_init().  See the !readme.', array(
          '!drupal_for_facebook' => l(t('Drupal for Facebook'), 'http://drupal.org/project/fb'),
          // This link should work with clean URLs
          // disabled.
          '!readme' => '<a href=' . base_path() . '/' . drupal_get_path('module', 'fb') . '/README.txt>README.txt</a>',
        ));
        drupal_set_message($message, 'error');
        watchdog('fb_devel', $message);
      }

      // path replacement sanity check
      global $base_path;
      if ($base_path == "/{$fb_app->canvas}/") {
        $message = t('Facebook canvas page matches Drupal base_path (%base_path).  This is currently not supported.', array(
          '%base_path' => $base_path,
        ));
        drupal_set_message($message, 'error');
        watchdog('fb_devel', $message);
      }
    }
  }
  else {
    if ($op == FB_APP_OP_EVENT) {
      $type = $data['event_type'];

      // Facebook has notified us of some event.
      $message = t('Facebook has notified the %label application of a %type event.', array(
        '%label' => $fb_app->label,
        '%type' => $type,
      ));
      $message .= dprint_r($data, 1);
      $message .= dprint_r($_REQUEST, 1);
      watchdog('fb_devel', $message);
    }
  }
}

/**
 * Provides a page with useful debug info.
 * 
 */
function fb_devel_page() {
  global $fb, $fb_app;
  global $user;
  if ($_REQUEST['require_login']) {
    $fb
      ->require_login();
  }
  if ($fb) {

    // These will work in a canvas page.
    drupal_set_message("in_fb_canvas returns " . $fb
      ->in_fb_canvas());
    drupal_set_message("get_loggedin_user returns " . $fb
      ->get_loggedin_user());
    drupal_set_message("current_url returns " . $fb
      ->current_url());
    drupal_set_message("base_url: " . $GLOBALS['base_url']);
    drupal_set_message("base_path: " . $GLOBALS['base_path']);
    drupal_set_message("url() returns: " . url());
    drupal_set_message("session_key is " . $fb->api_client->session_key);
  }
  if ($fbu = fb_get_fbu($user)) {
    $path = "fb/devel/fbu/{$fbu}";
    drupal_set_message(t("Learn more about the current user at !link", array(
      '!link' => l($path, $path),
    )));
  }
  dpm(fb_get_fbu($user), 'Facebook user via fb_get_fbu');

  //dpm($user, "Local user " . theme('username', $user));
  if ($GLOBALS['fb_connect_apikey']) {
    drupal_set_message("fb_connect_apikey = " . $GLOBALS['fb_connect_apikey']);
  }
  dpm($_COOKIE, 'cookie');
  dpm($_REQUEST, "Request");

  //dpm($fb_app, "fb_app");
  drupal_set_message("session_id returns " . session_id());

  //dpm($_SESSION, "session:");
  return "This is the facebook debug page.";
}

/**
 * A page which tests function which work with facebook user ids
 */
function fb_devel_fbu_page($fbu = NULL) {
  if ($fbu) {
    $output = "<p>Debug info about facebook id {$fbu}:</p>\n";
    $friends = fb_get_friends($fbu);

    //dpm($friends, "fb_get_friends($fbu) returned");
    $items = array();
    foreach ($friends as $_fbu) {
      $items[] = l($_fbu, "fb/devel/fbu/{$_fbu}");
    }
    if (count($items)) {
      $output .= "\n<p>Known friends:<ul><li>";
      $output .= implode("</li>\n  <li>", $items);
      $output .= "</li></ul></p>\n\n";
    }
    $local_friends = fb_user_get_local_friends($fbu);
    $items = array();
    foreach ($local_friends as $uid) {
      $account = user_load(array(
        'uid' => $uid,
      ));
      $items[] = theme('username', $account);
    }
    if (count($items)) {
      $output .= "\n<p>Local friends:<ul><li>";
      $output .= implode("</li>\n  <li>", $items);
      $output .= "</li></ul></p>\n\n";
    }
  }
  else {
    drupal_set_message("You have to specify a facebook user id.", 'error');
  }
  return $output;
}
function fb_devel_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $items[0]['info'] = t('Facebook Devel Page Info');
    return $items;
  }
  else {
    if ($op == 'view') {
      return array(
        'subject' => t('Facebook Devel Page Info'),
        'content' => drupal_get_form('fb_devel_canvas_info'),
      );
    }
  }
}
function fb_devel_canvas_info() {
  global $fb, $fb_app;
  global $user;
  global $base_url;
  global $base_path;
  $info = array();
  $nid = fb_settings(FB_SETTINGS_APP_NID);
  if ($fb) {
    if ($fb
      ->in_fb_canvas()) {
      $info['Page Status'] = t('Rendering FBML canvas page.');
    }
    else {
      if ($fb
        ->in_frame()) {
        $info['Page Status'] = t('Rendering iframe.');
      }
      else {
        if ($nid) {

          // Followed a link from within an iframe.
          $info['Page Status'] = t('Global fb instance is set (followed link in iframe, or handling a form).');
        }
        else {
          $info['Page Status'] = t('Connected via Facebook Connect');
        }
      }
    }
    $info['fb_facebook_user'] = fb_facebook_user();
  }
  else {
    $info['Page Status'] = t('Not a canvas page.');
  }
  $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['session_id'] = session_id();
  $info['session_name'] = session_name();
  $info['request'] = $_REQUEST;
  $info['fb_app'] = $fb_app;
  $info['session'] = $_SESSION;
  $info['cookies'] = $_COOKIE;
  $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;
}

Functions

Namesort descending Description
fb_devel_block
fb_devel_canvas_info
fb_devel_fb
fb_devel_fbu_page A page which tests function which work with facebook user ids
fb_devel_menu
fb_devel_page Provides a page with useful debug info.