You are here

function _phptemplate_variables in Drupal for Facebook 5

Same name and namespace in other branches
  1. 5.2 themes/fb_fbml/template.php \_phptemplate_variables()

File

themes/fb_fbml/template.php, line 14

Code

function _phptemplate_variables($hook, $vars = array()) {
  global $fb_app, $user;
  if ($hook == 'page' && function_exists('fb_canvas_is_iframe') && fb_canvas_is_iframe()) {
    $vars['template_file'] = 'iframe';
  }
  else {
    if ($hook == 'page') {

      // Include styles inline.  Facebook does not allow use to refer to
      // them in the header.
      $vars['styles'] = _phptemplate_callback('styles', $vars);

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

      // 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'] = '';
      }
      else {
        if ($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 advanced theming 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 ($vars['sidebar_left'] && $vars['sidebar_right']) {
        $body_classes[] = 'with-both-sidebars';
      }
      else {
        if ($vars['sidebar_right']) {
          $body_classes[] = 'with-sidebar-right';
        }
        else {
          if ($vars['sidebar_left']) {
            $body_classes[] = 'with-sidebar-left';
          }
        }
      }
      $vars['body_classes'] = implode(' ', $body_classes);
    }
    else {
      if ($hook == 'node') {
        if ($vars['teaser']) {
          $vars['template_file'] = 'node-teaser';
        }

        // TODO: could move this to phptemplate engine.
        if (count($vars['about'])) {
          $vars['about'] = drupal_render($vars['about']);
        }
        if (count($vars['children'])) {
          $vars['children'] = drupal_render($vars['children']);
        }
        if ($vars['extra_style']) {
          $vars['extra_style'] = drupal_render($vars['extra_style']);
        }
        if ($vars['teaser']) {
          $size = 'thumb';
        }
        else {
          $size = 'thumb';
        }

        // small is too big for now, change this when node header has been made larger to fit image.
        if ($fbu = fb_get_fbu($vars['uid'])) {
          $vars['picture'] = '<div class="picture"><fb:profile-pic uid="' . $fbu . '" linked="yes" size="' . $size . '" /></div>';
        }

        //drupal_set_message("node vars: " . dprint_r($vars, 1));
      }
    }
  }
  return $vars;
}