Factor out code to tell whether user's logged into FB into its own method

This commit is contained in:
Zach Copley 2009-06-30 00:49:59 +00:00
parent c01e8c0bd1
commit dfb4ed5265

View File

@ -147,17 +147,17 @@ class FBConnectPlugin extends Plugin
'href' => common_path('plugins/FBConnect/FBConnectPlugin.css'))); 'href' => common_path('plugins/FBConnect/FBConnectPlugin.css')));
} }
function onStartPrimaryNav($action) function loggedIn()
{ {
$user = common_current_user(); $user = common_current_user();
if ($user) { if (!empty($user)) {
$flink = Foreign_link::getByUserId($user->id, $flink = Foreign_link::getByUserId($user->id,
FACEBOOK_CONNECT_SERVICE); FACEBOOK_CONNECT_SERVICE);
$fbuid = 0; $fbuid = 0;
if ($flink) { if (!empty($flink)) {
try { try {
@ -173,9 +173,27 @@ class FBConnectPlugin extends Plugin
// Display Facebook Logged in indicator w/Facebook favicon // Display Facebook Logged in indicator w/Facebook favicon
if ($fbuid > 0) { if ($fbuid > 0) {
return $fbuid;
}
}
}
return null;
}
function onStartPrimaryNav($action)
{
$user = common_current_user();
if (!empty($user)) {
$fbuid = $this->loggedIn();
if (!empty($fbuid)) {
$action->elementStart('li', array('id' => 'nav_fb')); $action->elementStart('li', array('id' => 'nav_fb'));
$action->elementStart('fb:profile-pic', array('uid' => $flink->foreign_id, $action->elementStart('fb:profile-pic', array('uid' => $fbuid,
'linked' => 'false', 'linked' => 'false',
'width' => 16, 'width' => 16,
'height' => 16)); 'height' => 16));
@ -187,7 +205,6 @@ class FBConnectPlugin extends Plugin
$action->elementEnd('li'); $action->elementEnd('li');
} }
}
$action->menuItem(common_local_url('all', array('nickname' => $user->nickname)), $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
_('Home'), _('Personal profile and friends timeline'), false, 'nav_home'); _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
@ -207,7 +224,7 @@ class FBConnectPlugin extends Plugin
false, 'nav_invitecontact'); false, 'nav_invitecontact');
// Need to override the Logout link to make it do FB stuff // Need to override the Logout link to make it do FB stuff
if ($flink && $fbuid > 0) { if (!empty($fbuid)) {
$logout_url = common_local_url('logout'); $logout_url = common_local_url('logout');
$title = _('Logout from the site'); $title = _('Logout from the site');