summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/FBConnect/FBC_XDReceiver.php73
-rw-r--r--plugins/FBConnect/FBConnectAuth.php44
-rw-r--r--plugins/FBConnect/FBConnectLogin.php2
-rw-r--r--plugins/FBConnect/FBConnectPlugin.php129
-rw-r--r--plugins/FBConnect/FBConnectSettings.php89
-rw-r--r--plugins/FBConnect/xd_receiver.htm10
6 files changed, 238 insertions, 109 deletions
diff --git a/plugins/FBConnect/FBC_XDReceiver.php b/plugins/FBConnect/FBC_XDReceiver.php
new file mode 100644
index 000000000..57c98b4f1
--- /dev/null
+++ b/plugins/FBConnect/FBC_XDReceiver.php
@@ -0,0 +1,73 @@
+<?php
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+/*
+ * Generates the cross domain communication channel file
+ * (xd_receiver.html). By generating it we can add some caching
+ * instructions.
+ *
+ * See: http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel
+ */
+class FBC_XDReceiverAction extends Action
+{
+
+ /**
+ * Do we need to write to the database?
+ *
+ * @return boolean true
+ */
+
+ function isReadonly()
+ {
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ // Parent handling, including cache check
+ parent::handle($args);
+ $this->showPage();
+ }
+
+ function showPage()
+ {
+ // cache the xd_receiver
+ header('Cache-Control: max-age=225065900');
+ header('Expires:');
+ header('Pragma:');
+
+ $this->startXML('html',
+ '-//W3C//DTD XHTML 1.0 Strict//EN',
+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
+
+ $language = $this->getLanguage();
+
+ $this->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
+ 'xml:lang' => $language,
+ 'lang' => $language));
+ $this->elementStart('head');
+ $this->element('title', null, 'cross domain receiver page');
+ $this->element('script',
+ array('src' =>
+ 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.debug.js',
+ 'type' => 'text/javascript'), '');
+ $this->elementEnd('head');
+ $this->elementStart('body');
+ $this->elementEnd('body');
+
+ $this->elementEnd('html');
+ }
+
+}
+
diff --git a/plugins/FBConnect/FBConnectAuth.php b/plugins/FBConnect/FBConnectAuth.php
index 233eb83ab..4699ce636 100644
--- a/plugins/FBConnect/FBConnectAuth.php
+++ b/plugins/FBConnect/FBConnectAuth.php
@@ -62,7 +62,28 @@ class FBConnectauthAction extends Action
parent::handle($args);
if (common_is_real_login()) {
- $this->clientError(_('Already logged in.'));
+
+ // User is already logged in. Does she already have a linked Facebook acct?
+ $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_CONNECT_SERVICE);
+
+ if ($flink) {
+
+ // User already has a linked Facebook account and shouldn't be here
+ common_debug('There is already a local user (' . $flink->user_id .
+ ') linked with this Facebook (' . $this->fbuid . ').');
+
+ // We don't want these cookies
+ getFacebook()->clear_cookie_state();
+
+ $this->clientError(_('There is already a local user linked with this Facebook.'));
+
+ } else {
+
+ // User came from the Facebook connect settings tab, and
+ // probably just wants to link/relink their Facebook account
+ $this->connectUser();
+ }
+
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$token = $this->trimmed('token');
@@ -78,7 +99,7 @@ class FBConnectauthAction extends Action
}
$this->createNewUser();
} else if ($this->arg('connect')) {
- $this->connectUser();
+ $this->connectNewUser();
} else {
common_debug(print_r($this->args, true), __FILE__);
$this->showForm(_('Something weird happened.'),
@@ -259,7 +280,7 @@ class FBConnectauthAction extends Action
303);
}
- function connectUser()
+ function connectNewUser()
{
$nickname = $this->trimmed('nickname');
$password = $this->trimmed('password');
@@ -290,6 +311,23 @@ class FBConnectauthAction extends Action
$this->goHome($user->nickname);
}
+ function connectUser()
+ {
+ $user = common_current_user();
+
+ $result = $this->flinkUser($user->id, $this->fbuid);
+
+ if (!$result) {
+ $this->serverError(_('Error connecting user to Facebook.'));
+ return;
+ }
+
+ common_debug("Connected Facebook user $this->fbuid to local user $user->id");
+
+ // Return to Facebook connection settings tab
+ common_redirect(common_local_url('FBConnectSettings'), 303);
+ }
+
function tryLogin()
{
common_debug("Trying Facebook Login...");
diff --git a/plugins/FBConnect/FBConnectLogin.php b/plugins/FBConnect/FBConnectLogin.php
index 7989dc854..205086cd8 100644
--- a/plugins/FBConnect/FBConnectLogin.php
+++ b/plugins/FBConnect/FBConnectLogin.php
@@ -58,8 +58,6 @@ class FBConnectLoginAction extends Action
function showContent() {
$this->elementStart('fieldset');
-
-
$this->element('fb:login-button', array('onlogin' => 'goto_login()',
'length' => 'long'));
diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php
index ad5e47e47..a366985be 100644
--- a/plugins/FBConnect/FBConnectPlugin.php
+++ b/plugins/FBConnect/FBConnectPlugin.php
@@ -39,6 +39,7 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php';
require_once INSTALLDIR . '/plugins/FBConnect/FBConnectSettings.php';
require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php';
require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php';
+require_once INSTALLDIR . '/plugins/FBConnect/FBC_XDReceiver.php';
/**
* Plugin to enable Facebook Connect
@@ -62,27 +63,19 @@ class FBConnectPlugin extends Plugin
$m->connect('main/facebookconnect', array('action' => 'FBConnectAuth'));
$m->connect('main/facebooklogin', array('action' => 'FBConnectLogin'));
$m->connect('settings/facebook', array('action' => 'FBConnectSettings'));
+ $m->connect('xd_receiver.html', array('action' => 'FBC_XDReceiver'));
}
// Add in xmlns:fb
function onStartShowHTML($action)
{
- $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
- $_SERVER['HTTP_ACCEPT'] : null;
-
- // XXX: allow content negotiation for RDF, RSS, or XRDS
-
- $cp = common_accept_to_prefs($httpaccept);
- $sp = common_accept_to_prefs(PAGE_TYPE_PREFS);
-
- $type = common_negotiate_type($cp, $sp);
-
- if (!$type) {
- throw new ClientException(_('This page is not available in a '.
- 'media type you accept'), 406);
- }
-
- header('Content-Type: '.$type);
+ // XXX: Horrible hack to make Safari, FF2, and Chrome work with
+ // Facebook Connect. These browser cannot use Facebook's
+ // DOM parsing routines unless the mime type of the page is
+ // text/html even though Facebook Connect uses XHTML. This is
+ // A bug in Facebook Connect, and this is a temporary solution
+ // until they fix their JavaScript libs.
+ header('Content-Type: text/html');
$action->extraHeaders();
@@ -101,20 +94,27 @@ class FBConnectPlugin extends Plugin
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'),
- ' ');
+ // Note: this script needs to appear in the <body>
+ function onStartShowHeader($action)
+ {
$apikey = common_config('facebook', 'apikey');
$plugin_path = common_path('plugins/FBConnect');
$login_url = common_local_url('FBConnectAuth');
$logout_url = common_local_url('logout');
- $html = sprintf('<script type="text/javascript">FB.init("%s", "%s/xd_receiver.htm");
+ // XXX: Facebook says we don't need this FB_RequireFeatures(),
+ // but we actually do, for IE and Safari. Gar.
+
+ $html = sprintf('<script type="text/javascript">
+ window.onload = function () {
+ FB_RequireFeatures(
+ ["XFBML"],
+ function() {
+ FB.Facebook.init("%s", "../xd_receiver.html");
+ }
+ ); }
function goto_login() {
window.location = "%s";
@@ -123,11 +123,21 @@ class FBConnectPlugin extends Plugin
function goto_logout() {
window.location = "%s";
}
+ </script>', $apikey,
+ $login_url, $logout_url);
+
+ $action->raw($html);
+ }
- </script>', $apikey, $plugin_path, $login_url, $logout_url);
+ // Note: this script needs to appear as close as possible to </body>
+ function onEndShowFooter($action)
+ {
- $action->raw($html);
+ $action->element('script',
+ array('type' => 'text/javascript',
+ 'src' => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'),
+ '');
}
function onEndShowLaconicaStyles($action)
@@ -143,24 +153,8 @@ class FBConnectPlugin extends Plugin
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) {
@@ -195,9 +189,25 @@ class FBConnectPlugin extends Plugin
}
}
- // Need to override the Logout link to make it do FB stuff
+ $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');
- if ($fbuid > 0) {
+ // Need to override the Logout link to make it do FB stuff
+ if ($flink && $fbuid > 0) {
$logout_url = common_local_url('logout');
$title = _('Logout from the site');
@@ -258,21 +268,32 @@ class FBConnectPlugin extends Plugin
return true;
}
- function onEndLogout($action)
+ function onStartLogout($action)
{
- try {
+ $user = common_current_user();
+
+ $flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
+
+ $action->logout();
+
+ if ($flink) {
$facebook = getFacebook();
- $fbuid = $facebook->get_loggedin_user();
- if ($fbuid > 0) {
- $facebook->logout(common_local_url('public'));
- }
+ try {
+ $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());
+ } catch (Exception $e) {
+ common_log(LOG_WARNING, 'Could\'t logout of Facebook: ' .
+ $e->getMessage());
+ }
}
+
+ return true;
}
}
diff --git a/plugins/FBConnect/FBConnectSettings.php b/plugins/FBConnect/FBConnectSettings.php
index 7e255f43a..034ecebae 100644
--- a/plugins/FBConnect/FBConnectSettings.php
+++ b/plugins/FBConnect/FBConnectSettings.php
@@ -78,63 +78,73 @@ class FBConnectSettingsAction extends ConnectSettingsAction
function showContent()
{
$user = common_current_user();
-
$flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
+ $this->elementStart('form', array('method' => 'post',
+ 'id' => 'form_settings_facebook',
+ 'class' => 'form_settings',
+ 'action' =>
+ common_local_url('FBConnectSettings')));
+
if (!$flink) {
- $this->element('p', 'form_note',
+ $this->element('p', 'instructions',
_('There is no Facebook user connected to this account.'));
$this->element('fb:login-button', array('onlogin' => 'goto_login()',
'length' => 'long'));
- return;
- }
+ } else {
- $this->element('p', 'form_note',
- _('Connected Facebook user:'));
+ $this->element('p', 'form_note',
+ _('Connected Facebook user'));
+
+ $this->elementStart('p', array('class' => 'facebook-user-display'));
+ $this->elementStart('fb:profile-pic',
+ array('uid' => $flink->foreign_id,
+ 'size' => 'small',
+ 'linked' => 'true',
+ 'facebook-logo' => 'true'));
+ $this->elementEnd('fb:profile-pic');
+
+ $this->elementStart('fb:name', array('uid' => $flink->foreign_id,
+ 'useyou' => 'false'));
+ $this->elementEnd('fb:name');
+ $this->elementEnd('p');
- $this->elementStart('p', array('class' => 'facebook-user-display'));
- $this->elementStart('fb:profile-pic',
- array('uid' => $flink->foreign_id,
- 'size' => 'square',
- 'linked' => 'true',
- 'facebook-logo' => 'true'));
- $this->elementEnd('fb:profile-pic');
+ $this->hidden('token', common_session_token());
- $this->elementStart('fb:name', array('uid' => $flink->foreign_id));
- $this->elementEnd('fb:name');
- $this->elementEnd('p');
+ $this->elementStart('fieldset');
- $this->elementStart('form', array('method' => 'post',
- 'id' => 'form_settings_facebook',
- 'class' => 'form_settings',
- 'action' =>
- common_local_url('FBConnectSettings')));
+ $this->element('legend', null, _('Disconnect my account from Facebook'));
- $this->hidden('token', common_session_token());
+ if (!$user->password) {
- $this->elementStart('fieldset');
+ $this->elementStart('p', array('class' => 'form_guide'));
+ $this->text(_('Disconnecting your Faceboook ' .
+ 'would make it impossible to log in! Please '));
+ $this->element('a',
+ array('href' => common_local_url('passwordsettings')),
+ _('set a password'));
- $this->element('legend', null, _('Disconnect my account from Facebook'));
+ $this->text(_(' first.'));
+ $this->elementEnd('p');
+ } else {
- if (!$user->password) {
+ $note = 'Keep your %s account but disconnect from Facebook. ' .
+ 'You\'ll use your %s password to log in.';
- $this->elementStart('p', array('class' => 'form_guide'));
- $this->text(_('Disconnecting your Faceboook ' .
- 'would make it impossible to log in! Please '));
- $this->element('a',
- array('href' => common_local_url('passwordsettings')),
- _('set a password'));
+ $site = common_config('site', 'name');
- $this->text(_(' first.'));
- $this->elementEnd('p');
- } else {
- $this->submit('disconnect', _('Disconnect'));
- }
+ $this->element('p', 'instructions',
+ sprintf($note, $site, $site));
+
+ $this->submit('disconnect', _('Disconnect'));
+ }
+
+ $this->elementEnd('fieldset');
+ }
- $this->elementEnd('fieldset');
$this->elementEnd('form');
}
@@ -171,8 +181,7 @@ class FBConnectSettingsAction extends ConnectSettingsAction
try {
- // XXX: not sure what exactly to do here
-
+ // Clear FB Connect cookies out
$facebook = getFacebook();
$facebook->clear_cookie_state();
@@ -182,7 +191,7 @@ class FBConnectSettingsAction extends ConnectSettingsAction
$e->getMessage());
}
- $this->showForm(_('Facebook user disconnected.'), true);
+ $this->showForm(_('You have disconnected from Facebook.'), true);
} else {
$this->showForm(_('Not sure what you\'re trying to do.'));
diff --git a/plugins/FBConnect/xd_receiver.htm b/plugins/FBConnect/xd_receiver.htm
deleted file mode 100644
index 43fb2c4e4..000000000
--- a/plugins/FBConnect/xd_receiver.htm
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" >
-<head>
- <title>cross domain receiver page</title>
-</head>
-<body>
- <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.debug.js" type="text/javascript"></script>
-</body>
-</html>