- Show Facebook profile pic and favicon as dictated by Facebook Connnect policy

- Logout fixed, again (cleans up Facebook cookies now)
This commit is contained in:
Zach Copley 2009-05-22 00:54:22 +00:00
parent f25990cf8e
commit eaf2a98daf
5 changed files with 113 additions and 76 deletions

View File

@ -71,8 +71,6 @@ class FBCLoginGroupNav extends Widget
function show()
{
common_debug('FBCLoginGroupNav');
$this->action->elementStart('dl', array('id' => 'site_nav_local_views'));
$this->action->element('dt', null, _('Local views'));
$this->action->elementStart('dd');

View File

@ -50,7 +50,8 @@ class FBConnectauthAction extends Action
}
} catch (Exception $e) {
common_debug("Problem getting fbuid.");
common_log(LOG_WARNING, 'Problem getting Facebook uid: ' .
$e->getMessage());
}
return true;
@ -283,7 +284,7 @@ class FBConnectauthAction extends Action
} else {
common_debug("no flink found for fbuid: $this->fbuid");
common_debug("No flink found for fbuid: $this->fbuid");
$this->showForm(null, $this->bestNewNickname());
}
@ -306,8 +307,6 @@ class FBConnectauthAction extends Action
function flinkUser($user_id, $fbuid)
{
common_debug("flinkUser()");
$flink = new Foreign_link();
$flink->user_id = $user_id;
$flink->foreign_id = $fbuid;
@ -370,7 +369,10 @@ class FBConnectauthAction extends Action
// XXX: Consider moving this to lib/facebookutil.php
function getFacebookFields($fb_uid, $fields) {
try {
$infos = getFacebook()->api_client->users_getInfo($fb_uid, $fields);
$facebook = getFacebook();
$infos = $facebook->api_client->users_getInfo($fb_uid, $fields);
if (empty($infos)) {
return null;
@ -378,8 +380,9 @@ class FBConnectauthAction extends Action
return reset($infos);
} catch (Exception $e) {
error_log("Failure in the api when requesting " . join(",", $fields)
." on uid " . $fb_uid . " : ". $e->getMessage());
common_log(LOG_WARNING, "Facebook client failure when requesting " .
join(",", $fields) . " on uid " . $fb_uid .
" : ". $e->getMessage());
return null;
}
}

View File

@ -40,7 +40,6 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBConnectSettings.php';
require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php';
require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php';
/**
* Plugin to enable Facebook Connect
*
@ -53,7 +52,6 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php';
class FBConnectPlugin extends Plugin
{
function __construct()
{
parent::__construct();
@ -84,7 +82,6 @@ class FBConnectPlugin extends Plugin
'media type you accept'), 406);
}
header('Content-Type: '.$type);
$action->extraHeaders();
@ -95,18 +92,17 @@ class FBConnectPlugin extends Plugin
$language = $action->getLanguage();
$action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
$action->elementStart('html',
array('xmlns' => 'http://www.w3.org/1999/xhtml',
'xmlns:fb' => 'http://www.facebook.com/2008/fbml',
'xml:lang' => $language,
'lang' => $language));
return false;
}
function onEndShowLaconicaScripts($action)
{
$action->element('script',
array('type' => 'text/javascript',
'src' => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'),
@ -140,32 +136,6 @@ class FBConnectPlugin extends Plugin
if ($user) {
$flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
if ($flink) {
$facebook = getFacebook();
if ($facebook->api_client->users_isAppUser($flink->foreign_id) ||
$facebook->api_client->added) {
// XXX: We need to replace this with a proper mini-icon and only after
// checing the FB Connect JavaScript lib method to see what the Connect
// status is. Checking Connect status looks to be impossible with the
// PHP client.
$action->elementStart('li');
$action->elementStart('fb:profile-pic', array('uid' => $flink->foreign_id,
'facebook-logo' => 'true',
'linked' => 'false',
'width' => 32,
'height' => 32));
$action->elementEnd('fb:profile-pic');
$action->elementEnd('li');
}
}
$action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
_('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
$action->menuItem(common_local_url('profilesettings'),
@ -183,8 +153,45 @@ class FBConnectPlugin extends Plugin
common_config('site', 'name')),
false, 'nav_invitecontact');
$flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
$fbuid = 0;
if ($flink) {
try {
$facebook = getFacebook();
$fbuid = getFacebook()->get_loggedin_user();
} catch (Exception $e) {
common_log(LOG_WARNING,
'Problem getting Facebook client: ' .
$e->getMessage());
}
// Display Facebook Logged in indicator w/Facebook favicon
if ($fbuid > 0) {
$action->elementStart('li', array('id' => 'nav_fb'));
$action->elementStart('fb:profile-pic', array('uid' => $flink->foreign_id,
'linked' => 'false',
'width' => 16,
'height' => 16));
$action->elementEnd('fb:profile-pic');
$iconurl = common_path('/plugins/FBConnect/fbfavicon.ico');
$action->element('img', array('src' => $iconurl));
$action->elementEnd('li');
}
}
// Need to override the Logout link to make it do FB stuff
if ($fbuid > 0) {
$logout_url = common_local_url('logout');
$title = _('Logout from the site');
$text = _('Logout');
@ -195,6 +202,10 @@ class FBConnectPlugin extends Plugin
$action->raw($html);
} else {
$action->menuItem(common_local_url('logout'),
_('Logout'), _('Logout from the site'), false, 'nav_logout');
}
}
else {
if (!common_config('site', 'closed')) {
@ -220,7 +231,7 @@ class FBConnectPlugin extends Plugin
$action_name = get_class($action);
$login_actions = array('LoginAction', 'RegisterAction',
'OpenidloginAction', 'FacebookStart');
'OpenidloginAction', 'FBConnectLoginAction');
if (in_array($action_name, $login_actions)) {
$nav = new FBCLoginGroupNav($action);
@ -240,6 +251,21 @@ class FBConnectPlugin extends Plugin
return true;
}
function onEndLogout($action)
{
try {
$facebook = getFacebook();
$fbuid = $facebook->get_loggedin_user();
if ($fbuid > 0) {
$facebook->logout(common_local_url('public'));
}
} catch (Exception $e) {
common_log(LOG_WARNING, 'Could\'t logout of Facebook: ' .
$e->getMessage());
}
}
}

View File

@ -169,8 +169,18 @@ class FBConnectSettingsAction extends ConnectSettingsAction
return;
}
try {
// XXX: not sure what exactly to do here
$facebook = getFacebook();
$facebook->logout();
$facebook->clear_cookie_state();
} catch (Exception $e) {
common_log(LOG_WARNING,
'Couldn\'t clear Facebook cookies: ' .
$e->getMessage());
}
$this->showForm(_('Facebook user disconnected.'), true);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB