You are here

function fbconnect_invite_block in Facebook Connect 6.2

Implements hook_block().

File

fbconnect_invite/fbconnect_invite.module, line 63
@todo.

Code

function fbconnect_invite_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Facebook Friends');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
    case 'view':
      $fbuid = fbconnect_get_fbuid(TRUE);
      if (user_is_logged_in() && $fbuid) {
        $cid = 'fbconnect:' . $fbuid;
        $cached = cache_get($cid, 'cache_block');
        if ($cached->data) {
          $content = $cached->data;
        }
        else {
          $friends = fbconnect_get_connected_friends($fbuid);
          if ($friends) {
            foreach ($friends as $friend) {
              $row[] = theme('username', $friend);
            }
            $content = theme('item_list', $row);
            cache_set($cid, $content, 'cache_block', time() + 3600);
          }
        }
        $link_options = array();
        if (!drupal_is_front_page()) {
          $link_options = array(
            'query' => drupal_get_destination(),
          );
        }
        $invite_link = l(t('Invite Friends'), 'fbconnect/invite/friends', $link_options);
        $blocks['subject'] = t('Facebook Friends');
        $blocks['content'] = $invite_link . $content;
        return $blocks;
      }
      break;
  }
}