You are here

function fb_fbml_preprocess_page in Drupal for Facebook 6.2

Theme engine calls this preprocess "hook" before rendering a page.

We change template for iframes, add styles and fbjs.

File

themes/fb_fbml/template.php, line 13
Logic needed for FBML theme.

Code

function fb_fbml_preprocess_page(&$vars, $hook) {
  global $_fb_app, $user, $conf;
  if (fb_is_iframe_canvas()) {

    // Iframe in a canvas
    $vars['template_file'] = 'iframe';
  }
  else {

    // FBML canvas page
    _fb_fbml_menu_hack();

    // Add our own stylesheet
    drupal_add_css(path_to_theme() . '/styles_fbml.css', 'theme', 'fbml');

    // On profile tabs, we must preprocess.  Kind of hacky, but so is facebook.
    $preprocess_css = $conf['preprocess_css'];
    if (fb_is_profile_tab()) {
      $conf['preprocess_css'] = TRUE;
    }
    $vars['styles'] = drupal_get_css();
    $conf['preprocess_css'] = $preprocess_css;

    // Restore original value
    // Include only Facebook aware javascript.
    $vars['fbjs'] = drupal_get_js('fbml');

    // Enforce that only admins see admin block.  This can be done (more
    // cleanly?) elsewhere.  But we're doing it here to make sure.
    if (!user_access('access administration pages')) {
      $vars['admin'] = '';
    }
    elseif ($vars['admin']) {
      $vars['admin'] = "<div class=\"region admin_sidebar\">\n" . $vars['admin'] . "\n</div><!-- end admin sidebar-->";
    }

    // Change 'Home' in breadcrumbs.
    $crumbs = drupal_get_breadcrumb();
    if (count($crumbs) && strpos($crumbs[0], t('Home'))) {
      $crumbs[0] = l(t($_fb_app->title), '');
      $vars['breadcrumb'] = theme('breadcrumb', $crumbs);
    }

    // Style page differently depending on which sidebars are present.
    // Approach copied from Zen theme.
    // allows styling based on context (home page, node of certain type, etc.)
    $body_classes = array();
    $body_classes[] = $vars['is_front'] ? 'front' : 'not-front';
    $body_classes[] = $user->uid > 0 ? 'logged-in' : 'not-logged-in';
    if (isset($vars['left']) && isset($vars['right'])) {
      $body_classes[] = 'with-both-sidebars';
    }
    elseif ($vars['right']) {
      $body_classes[] = 'with-sidebar-right';
    }
    elseif ($vars['left']) {
      $body_classes[] = 'with-sidebar-left';
    }

    // new facebook pages are wider
    if ($_REQUEST['fb_sig_in_new_facebook']) {
      $body_classes[] = 'in-new-facebook';
    }

    // Regions
    $region_list = array(
      'prefaces' => array(
        'preface_first',
        'preface_middle',
        'preface_last',
      ),
    );
    foreach ($region_list as $sub_region_key => $sub_region_list) {
      $active_regions = array();
      foreach ($sub_region_list as $region_item) {
        if ($vars[$region_item]) {
          $active_regions[] = $region_item;
        }
      }
      $vars[$sub_region_key . '_class'] = $sub_region_key . '-' . strval(count($active_regions));
      $vars[$sub_region_key . '_count'] = count($active_regions);
    }
    $vars['body_classes'] = implode(' ', $body_classes);
  }
}