- 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:
parent
f25990cf8e
commit
eaf2a98daf
@ -71,26 +71,24 @@ class FBCLoginGroupNav extends Widget
|
|||||||
|
|
||||||
function show()
|
function show()
|
||||||
{
|
{
|
||||||
common_debug('FBCLoginGroupNav');
|
|
||||||
|
|
||||||
$this->action->elementStart('dl', array('id' => 'site_nav_local_views'));
|
$this->action->elementStart('dl', array('id' => 'site_nav_local_views'));
|
||||||
$this->action->element('dt', null, _('Local views'));
|
$this->action->element('dt', null, _('Local views'));
|
||||||
$this->action->elementStart('dd');
|
$this->action->elementStart('dd');
|
||||||
|
|
||||||
// action => array('prompt', 'title')
|
// action => array('prompt', 'title')
|
||||||
$menu = array();
|
$menu = array();
|
||||||
|
|
||||||
$menu['login'] = array(_('Login'),
|
$menu['login'] = array(_('Login'),
|
||||||
_('Login with a username and password'));
|
_('Login with a username and password'));
|
||||||
|
|
||||||
if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
|
if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
|
||||||
$menu['register'] = array(_('Register'),
|
$menu['register'] = array(_('Register'),
|
||||||
_('Sign up for a new account'));
|
_('Sign up for a new account'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu['openidlogin'] = array(_('OpenID'),
|
$menu['openidlogin'] = array(_('OpenID'),
|
||||||
_('Login or register with OpenID'));
|
_('Login or register with OpenID'));
|
||||||
|
|
||||||
$menu['FBConnectLogin'] = array(_('Facebook'),
|
$menu['FBConnectLogin'] = array(_('Facebook'),
|
||||||
_('Login or register using Facebook'));
|
_('Login or register using Facebook'));
|
||||||
|
|
||||||
@ -105,7 +103,7 @@ class FBCLoginGroupNav extends Widget
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->action->elementEnd('ul');
|
$this->action->elementEnd('ul');
|
||||||
|
|
||||||
$this->action->elementEnd('dd');
|
$this->action->elementEnd('dd');
|
||||||
$this->action->elementEnd('dl');
|
$this->action->elementEnd('dl');
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,8 @@ class FBConnectauthAction extends Action
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_debug("Problem getting fbuid.");
|
common_log(LOG_WARNING, 'Problem getting Facebook uid: ' .
|
||||||
|
$e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -283,7 +284,7 @@ class FBConnectauthAction extends Action
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
common_debug("no flink found for fbuid: $this->fbuid");
|
common_debug("No flink found for fbuid: $this->fbuid");
|
||||||
|
|
||||||
$this->showForm(null, $this->bestNewNickname());
|
$this->showForm(null, $this->bestNewNickname());
|
||||||
}
|
}
|
||||||
@ -306,8 +307,6 @@ class FBConnectauthAction extends Action
|
|||||||
|
|
||||||
function flinkUser($user_id, $fbuid)
|
function flinkUser($user_id, $fbuid)
|
||||||
{
|
{
|
||||||
common_debug("flinkUser()");
|
|
||||||
|
|
||||||
$flink = new Foreign_link();
|
$flink = new Foreign_link();
|
||||||
$flink->user_id = $user_id;
|
$flink->user_id = $user_id;
|
||||||
$flink->foreign_id = $fbuid;
|
$flink->foreign_id = $fbuid;
|
||||||
@ -370,7 +369,10 @@ class FBConnectauthAction extends Action
|
|||||||
// XXX: Consider moving this to lib/facebookutil.php
|
// XXX: Consider moving this to lib/facebookutil.php
|
||||||
function getFacebookFields($fb_uid, $fields) {
|
function getFacebookFields($fb_uid, $fields) {
|
||||||
try {
|
try {
|
||||||
$infos = getFacebook()->api_client->users_getInfo($fb_uid, $fields);
|
|
||||||
|
$facebook = getFacebook();
|
||||||
|
|
||||||
|
$infos = $facebook->api_client->users_getInfo($fb_uid, $fields);
|
||||||
|
|
||||||
if (empty($infos)) {
|
if (empty($infos)) {
|
||||||
return null;
|
return null;
|
||||||
@ -378,9 +380,10 @@ class FBConnectauthAction extends Action
|
|||||||
return reset($infos);
|
return reset($infos);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log("Failure in the api when requesting " . join(",", $fields)
|
common_log(LOG_WARNING, "Facebook client failure when requesting " .
|
||||||
." on uid " . $fb_uid . " : ". $e->getMessage());
|
join(",", $fields) . " on uid " . $fb_uid .
|
||||||
return null;
|
" : ". $e->getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBConnectSettings.php';
|
|||||||
require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php';
|
require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php';
|
||||||
require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php';
|
require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin to enable Facebook Connect
|
* Plugin to enable Facebook Connect
|
||||||
*
|
*
|
||||||
@ -53,7 +52,6 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php';
|
|||||||
|
|
||||||
class FBConnectPlugin extends Plugin
|
class FBConnectPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -84,29 +82,27 @@ class FBConnectPlugin extends Plugin
|
|||||||
'media type you accept'), 406);
|
'media type you accept'), 406);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
header('Content-Type: '.$type);
|
header('Content-Type: '.$type);
|
||||||
|
|
||||||
$action->extraHeaders();
|
$action->extraHeaders();
|
||||||
|
|
||||||
$action->startXML('html',
|
$action->startXML('html',
|
||||||
'-//W3C//DTD XHTML 1.0 Strict//EN',
|
'-//W3C//DTD XHTML 1.0 Strict//EN',
|
||||||
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
|
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
|
||||||
|
|
||||||
$language = $action->getLanguage();
|
$language = $action->getLanguage();
|
||||||
|
|
||||||
$action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
|
$action->elementStart('html',
|
||||||
'xmlns:fb' => 'http://www.facebook.com/2008/fbml',
|
array('xmlns' => 'http://www.w3.org/1999/xhtml',
|
||||||
'xml:lang' => $language,
|
'xmlns:fb' => 'http://www.facebook.com/2008/fbml',
|
||||||
'lang' => $language));
|
'xml:lang' => $language,
|
||||||
|
'lang' => $language));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onEndShowLaconicaScripts($action)
|
function onEndShowLaconicaScripts($action)
|
||||||
{
|
{
|
||||||
|
|
||||||
$action->element('script',
|
$action->element('script',
|
||||||
array('type' => 'text/javascript',
|
array('type' => 'text/javascript',
|
||||||
'src' => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'),
|
'src' => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'),
|
||||||
@ -140,77 +136,92 @@ class FBConnectPlugin extends Plugin
|
|||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
|
|
||||||
|
$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'),
|
||||||
|
_('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
|
||||||
|
if (common_config('xmpp', 'enabled')) {
|
||||||
|
$action->menuItem(common_local_url('imsettings'),
|
||||||
|
_('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
|
||||||
|
} else {
|
||||||
|
$action->menuItem(common_local_url('smssettings'),
|
||||||
|
_('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
|
||||||
|
}
|
||||||
|
$action->menuItem(common_local_url('invite'),
|
||||||
|
_('Invite'),
|
||||||
|
sprintf(_('Invite friends and colleagues to join you on %s'),
|
||||||
|
common_config('site', 'name')),
|
||||||
|
false, 'nav_invitecontact');
|
||||||
|
|
||||||
$flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
|
$flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
|
||||||
|
$fbuid = 0;
|
||||||
|
|
||||||
if ($flink) {
|
if ($flink) {
|
||||||
|
|
||||||
$facebook = getFacebook();
|
try {
|
||||||
|
|
||||||
if ($facebook->api_client->users_isAppUser($flink->foreign_id) ||
|
$facebook = getFacebook();
|
||||||
$facebook->api_client->added) {
|
$fbuid = getFacebook()->get_loggedin_user();
|
||||||
|
|
||||||
// XXX: We need to replace this with a proper mini-icon and only after
|
} catch (Exception $e) {
|
||||||
// checing the FB Connect JavaScript lib method to see what the Connect
|
common_log(LOG_WARNING,
|
||||||
// status is. Checking Connect status looks to be impossible with the
|
'Problem getting Facebook client: ' .
|
||||||
// PHP client.
|
$e->getMessage());
|
||||||
|
|
||||||
$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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$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'),
|
|
||||||
_('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
|
|
||||||
if (common_config('xmpp', 'enabled')) {
|
|
||||||
$action->menuItem(common_local_url('imsettings'),
|
|
||||||
_('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
|
|
||||||
} else {
|
|
||||||
$action->menuItem(common_local_url('smssettings'),
|
|
||||||
_('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
|
|
||||||
}
|
|
||||||
$action->menuItem(common_local_url('invite'),
|
|
||||||
_('Invite'),
|
|
||||||
sprintf(_('Invite friends and colleagues to join you on %s'),
|
|
||||||
common_config('site', 'name')),
|
|
||||||
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
|
||||||
|
|
||||||
$logout_url = common_local_url('logout');
|
if ($fbuid > 0) {
|
||||||
$title = _('Logout from the site');
|
|
||||||
$text = _('Logout');
|
|
||||||
|
|
||||||
$html = sprintf('<li id="nav_logout"><a href="%s" title="%s" ' .
|
$logout_url = common_local_url('logout');
|
||||||
'onclick="FB.Connect.logout(function() { goto_logout() })">%s</a></li>',
|
$title = _('Logout from the site');
|
||||||
|
$text = _('Logout');
|
||||||
|
|
||||||
|
$html = sprintf('<li id="nav_logout"><a href="%s" title="%s" ' .
|
||||||
|
'onclick="FB.Connect.logout(function() { goto_logout() })">%s</a></li>',
|
||||||
$logout_url, $title, $text);
|
$logout_url, $title, $text);
|
||||||
|
|
||||||
$action->raw($html);
|
$action->raw($html);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$action->menuItem(common_local_url('logout'),
|
||||||
|
_('Logout'), _('Logout from the site'), false, 'nav_logout');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!common_config('site', 'closed')) {
|
if (!common_config('site', 'closed')) {
|
||||||
$action->menuItem(common_local_url('register'),
|
$action->menuItem(common_local_url('register'),
|
||||||
_('Register'), _('Create an account'), false, 'nav_register');
|
_('Register'), _('Create an account'), false, 'nav_register');
|
||||||
}
|
}
|
||||||
$action->menuItem(common_local_url('openidlogin'),
|
$action->menuItem(common_local_url('openidlogin'),
|
||||||
_('OpenID'), _('Login with OpenID'), false, 'nav_openid');
|
_('OpenID'), _('Login with OpenID'), false, 'nav_openid');
|
||||||
$action->menuItem(common_local_url('login'),
|
$action->menuItem(common_local_url('login'),
|
||||||
_('Login'), _('Login to the site'), false, 'nav_login');
|
_('Login'), _('Login to the site'), false, 'nav_login');
|
||||||
}
|
}
|
||||||
|
|
||||||
$action->menuItem(common_local_url('doc', array('title' => 'help')),
|
$action->menuItem(common_local_url('doc', array('title' => 'help')),
|
||||||
_('Help'), _('Help me!'), false, 'nav_help');
|
_('Help'), _('Help me!'), false, 'nav_help');
|
||||||
$action->menuItem(common_local_url('peoplesearch'),
|
$action->menuItem(common_local_url('peoplesearch'),
|
||||||
_('Search'), _('Search for people or text'), false, 'nav_search');
|
_('Search'), _('Search for people or text'), false, 'nav_search');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -220,7 +231,7 @@ class FBConnectPlugin extends Plugin
|
|||||||
$action_name = get_class($action);
|
$action_name = get_class($action);
|
||||||
|
|
||||||
$login_actions = array('LoginAction', 'RegisterAction',
|
$login_actions = array('LoginAction', 'RegisterAction',
|
||||||
'OpenidloginAction', 'FacebookStart');
|
'OpenidloginAction', 'FBConnectLoginAction');
|
||||||
|
|
||||||
if (in_array($action_name, $login_actions)) {
|
if (in_array($action_name, $login_actions)) {
|
||||||
$nav = new FBCLoginGroupNav($action);
|
$nav = new FBCLoginGroupNav($action);
|
||||||
@ -240,6 +251,21 @@ class FBConnectPlugin extends Plugin
|
|||||||
return true;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,8 +169,18 @@ class FBConnectSettingsAction extends ConnectSettingsAction
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$facebook = getFacebook();
|
try {
|
||||||
$facebook->logout();
|
|
||||||
|
// XXX: not sure what exactly to do here
|
||||||
|
|
||||||
|
$facebook = getFacebook();
|
||||||
|
$facebook->clear_cookie_state();
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
common_log(LOG_WARNING,
|
||||||
|
'Couldn\'t clear Facebook cookies: ' .
|
||||||
|
$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$this->showForm(_('Facebook user disconnected.'), true);
|
$this->showForm(_('Facebook user disconnected.'), true);
|
||||||
|
|
||||||
|
BIN
plugins/FBConnect/fbfavicon.ico
Normal file
BIN
plugins/FBConnect/fbfavicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Loading…
Reference in New Issue
Block a user