You are here

function fb_connect_block_view in Drupal for Facebook 7.4

Same name and namespace in other branches
  1. 7.3 fb_connect.module \fb_connect_block_view()

File

./fb_connect.module, line 192

Code

function fb_connect_block_view($delta = '') {

  // Hide block on tabs, where the $fbu is actually the page, not the user.

  //if (!fb_is_tab()) {
  if (TRUE) {

    // XXX
    if (strpos($delta, 'login_') === 0) {

      // Login block
      $fba = substr($delta, 6);

      // length of 'login_'
      if ($fba == 'primary') {
        $app = fb_get_app();
      }
      else {

        // TODO: load details for client_id.

        //dpm(func_get_args(), __FUNCTION__);
        return NULL;
      }
      if (!empty($app)) {
        if (!empty($_SESSION['fb'][$app['fba']])) {
          $sdata = $_SESSION['fb'][$app['fba']];
        }

        /*
        $token = fb_user_token($app);
        dpm($token, __FUNCTION__);
        if ($token) {
          try {
            // debug. should not be needed.
            $me = fb_graph('me', $token);
          }
          catch (Exception $e) {
            fb_log_exception($e, __FUNCTION__);
          }
        }
        */
        $defaults = variable_get('fb_connect_block_' . $delta, _fb_connect_block_login_defaults());

        // Render both connected and not-connected markup to the page.  Javascript will show or hide it.
        $subject_connected = $defaults['connected']['title'];
        $content_connected = $defaults['connected']['body']['value'];
        if (user_is_anonymous()) {
          $subject = $defaults['anon_not_connected']['title'];
          $content = $defaults['anon_not_connected']['body']['value'];
          $format = $defaults['anon_not_connected']['body']['format'];
        }
        else {
          $subject = $defaults['user_not_connected']['title'];
          $content = $defaults['user_not_connected']['body']['value'];
          $format = $defaults['user_not_connected']['body']['format'];
        }

        // substitute perms
        $perms = array();
        drupal_alter('fb_required_perms', $perms);
        $content = str_replace('!perms', implode(',', $perms), $content);

        // Filter output according to settings in block configuration
        $subject = check_plain($subject);
        if ($format) {
          $content = check_markup($content, $format, '', FALSE);
        }
        $subject_connected = check_plain($subject_connected);
        if ($format_connected = $defaults['connected']['body']['format']) {
          $content_connected = check_markup($content_connected, $format_connected, FALSE);
        }
        $block = array(
          // Theme fb_markup uses javascript to show/hide the right markup.
          'subject' => theme('fb_markup', array(
            'not_connected' => $subject,
            'connected' => $subject_connected,
          )),
          'content' => theme('fb_markup', array(
            'not_connected' => $content,
            'connected' => $content_connected,
          )),
        );
        return $block;
      }
    }
  }
}