You are here

function fb_tab_fb in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 7.3 fb_tab.module \fb_tab_fb()

Implementation of hook_fb

Parameters

$op:

$data -- data payload:

$return:

File

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

Code

function fb_tab_fb($op, $data, &$return) {
  $fb = isset($data['fb']) ? $data['fb'] : NULL;
  $fb_app = isset($data['fb_app']) ? $data['fb_app'] : NULL;
  if ($op == FB_OP_POST_INIT) {

    // Include our admin hooks.
    if (fb_is_fb_admin_page()) {
      require drupal_get_path('module', 'fb_tab') . '/fb_tab.admin.inc';
    }
    if (fb_is_tab()) {

      // Include our javascript.
      drupal_add_js(array(
        'fb_tab' => array(
          'fbu' => fb_facebook_user(),
          'uid' => $GLOBALS['user']->uid,
          'canvas' => $fb_app->canvas,
        ),
      ), 'setting');
      drupal_add_js(drupal_get_path('module', 'fb_tab') . '/fb_tab.js');
    }
  }
  elseif ($op == FB_OP_CURRENT_APP && fb_is_tab()) {
    if ($id = fb_settings(FB_SETTINGS_CB)) {

      // Using fb_url_rewrite.
      $fb_app = fb_get_app(array(
        'id' => $id,
      ));
      if (!$fb_app) {

        // DEPRECATED.  For backward compatibility, accept apikey in FB_SETTINGS_CB
        $fb_app = fb_get_app(array(
          'apikey' => $id,
        ));
      }
    }
    elseif ($id = fb_settings(FB_SETTINGS_ID)) {

      // New SDK includes ID when session is present.
      $fb_app = fb_get_app(array(
        'id' => $id,
      ));
    }
    elseif (isset($_REQUEST['fb_sig_api_key'])) {
      $return = fb_get_app(array(
        'apikey' => $_REQUEST['fb_sig_api_key'],
      ));
    }
    if ($fb_app) {
      $return = $fb_app;
    }
  }
  elseif ($op == FB_OP_INITIALIZE) {
    if (fb_is_tab()) {
      $config = _fb_tab_get_app_config($fb_app);
      if (!isset($GLOBALS['custom_theme'])) {
        $GLOBALS['custom_theme'] = $config['custom_theme'];
      }
      if (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_PAGE_TAB && (variable_get(FB_TAB_VAR_PROCESS_IFRAME, TRUE) || variable_get(FB_TAB_VAR_PROCESS_ABSOLUTE, TRUE))) {

        // Process iframe
        $use_ob = TRUE;
      }
      elseif (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_PROFILE && variable_get(FB_TAB_VAR_PROCESS_FBML, TRUE)) {

        // Process FBML
        $use_ob = TRUE;
      }
      else {
        $use_ob = FALSE;
      }

      // Hack to init the theme before _drupal_maintenance_theme initializes the wrong one.
      if (variable_get('site_offline', FALSE)) {
        $dummy = theme('dummy');
      }

      // Store entire page in output buffer.  Will post-process on exit.
      if ($use_ob) {
        ob_start();
        $GLOBALS['fb_tab_post_process'] = TRUE;
      }

      // Override what Drupal renders.
      if (arg(0) == 'fb_tab' && arg(1) == 'view') {

        // Do not override fb_tab/config.
        $sr = $fb
          ->getSignedRequest();
        if ($sr['page'] && $sr['page']['liked'] && $config['profile_tab_url_liked']) {
          $path = $config['profile_tab_url_liked'];
        }
        else {
          $path = $config['profile_tab_url'];
        }
        if ($path && $path != FB_TAB_PATH_VIEW) {

          // Tell Drupal what to really render.
          menu_set_active_item(drupal_get_normal_path($path));
        }
      }
    }
  }
  elseif ($op == FB_OP_EXIT && fb_is_tab()) {
    if (isset($GLOBALS['fb_tab_post_process']) && $GLOBALS['fb_tab_post_process']) {
      $output = ob_get_contents();
      ob_end_clean();
      include_once drupal_get_path('module', 'fb') . '/fb.process.inc';
      if (variable_get(FB_TAB_VAR_PROCESS_TO_CANVAS, TRUE)) {
        $to_canvas = $fb_app->canvas;
      }
      else {
        $to_canvas = FALSE;
      }
      if (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_PAGE_TAB) {

        // Process iframe
        $output = fb_process($output, array(
          'add_target' => '_top',
          'absolute_links' => variable_get(FB_TAB_VAR_PROCESS_ABSOLUTE, TRUE),
          'relative_links' => variable_get(FB_TAB_VAR_PROCESS_IFRAME, TRUE),
          'to_canvas' => $to_canvas,
        ));
      }
      elseif (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_PROFILE) {

        // Process FBML (deprecated)
        $output = fb_process($output, array(
          'add_target' => FALSE,
          'absolute_links' => TRUE,
          'to_canvas' => $to_canvas,
        ));
      }
      if (isset($output)) {
        print $output;
      }
    }
  }
}