From 4f5630099fd0042170350f18512dc2cbe3b896b2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 4 Jun 2009 21:33:04 +0000 Subject: Facebook Connect auth finally works with all major browsers! --- plugins/FBConnect/FBC_XDReceiver.php | 73 +++++++++++++++++++++++++++++++++++ plugins/FBConnect/FBConnectLogin.php | 2 - plugins/FBConnect/FBConnectPlugin.php | 63 +++++++++++++++++------------- plugins/FBConnect/xd_receiver.htm | 10 ----- 4 files changed, 110 insertions(+), 38 deletions(-) create mode 100644 plugins/FBConnect/FBC_XDReceiver.php delete mode 100644 plugins/FBConnect/xd_receiver.htm 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 @@ +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/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 c85ef432d..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 + 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('', $apikey, + $login_url, $logout_url); - ', $apikey, $plugin_path, $login_url, $logout_url); + $action->raw($html); + } + // Note: this script needs to appear as close as possible to - $action->raw($html); + function onEndShowFooter($action) + { + + $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,7 +153,8 @@ class FBConnectPlugin extends Plugin if ($user) { - $flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE); + $flink = Foreign_link::getByUserId($user->id, + FACEBOOK_CONNECT_SERVICE); $fbuid = 0; if ($flink) { 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 @@ - - - - cross domain receiver page - - - - - -- cgit v1.2.3-54-g00ecf