You are here

function fbconnect_invite_block_view in Facebook Connect 8.2

Same name and namespace in other branches
  1. 7.2 fbconnect_invite/fbconnect_invite.module \fbconnect_invite_block_view()

Implements hook_block_view().

File

fbconnect_invite/fbconnect_invite.module, line 74

Code

function fbconnect_invite_block_view($delta) {
  $fbuid = fbconnect_get_fbuid(TRUE);
  if (user_is_logged_in() && $fbuid) {
    $cid = 'fbconnect:' . $fbuid;
    $cached = cache_get($cid, 'cache_block');
    if ($cached !== FALSE) {
      $content = $cached->data;
    }
    else {
      $friends = fbconnect_get_connected_friends($fbuid);
      if ($friends) {
        foreach ($friends as $friend) {
          $row[] = theme('username', array(
            'account' => $friend,
          ));
        }
        $content = theme('item_list', array(
          'items' => $row,
        ));
        cache_set($cid, $content, 'cache_block', REQUEST_TIME + 3600);
      }
      else {

        // no friends, no content
        $content = '';
      }
    }
    $link_options = array();
    if (!drupal_is_front_page()) {
      $link_options = array(
        'query' => drupal_get_destination(),
      );
    }
    $invite_link = l(t('Invite Friends from FB'), 'fbconnect/invite/friends', $link_options);
    $blocks['subject'] = t('Facebook Friends');
    $blocks['content'] = $invite_link . $content;
    return $blocks;
  }
}