We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 3a267aa5 authored by Evan Prodromou's avatar Evan Prodromou

Merge remote-tracking branch 'origin/testing' into testing

parents a9f83008 ec53e68c
......@@ -44,20 +44,18 @@ class Foreign_user extends Managed_DataObject
);
}
// XXX: This only returns a 1->1 single obj mapping. Change? Or make
// a getForeignUsers() that returns more than one? --Zach
static function getForeignUser($id, $service) {
$fuser = new Foreign_user();
$fuser->whereAdd("service = $service");
$fuser->whereAdd("id = $id");
$fuser->id = $id;
$fuser->service = $service;
$fuser->limit(1);
if ($fuser->find()) {
$fuser->fetch();
return $fuser;
}
$result = $fuser->find(true);
return null;
return empty($result) ? null : $fuser;
}
static function getByNickname($nickname, $service)
......
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
* Copyright (C) 2010-2011, StatusNet, Inc.
*
* A plugin for integrating Facebook with StatusNet. Includes single-sign-on
* and publishing notices to Facebook using Facebook's Graph API.
......@@ -21,7 +21,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Pugin
* @category Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
......@@ -41,7 +41,7 @@ define("FACEBOOK_SERVICE", 2);
* @category Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @copyright 2010-2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
......@@ -103,11 +103,10 @@ class FacebookBridgePlugin extends Plugin
{
$dir = dirname(__FILE__);
//common_debug("class = " . $cls);
switch ($cls)
{
case 'Facebook': // Facebook PHP SDK
include_once $dir . '/extlib/base_facebook.php';
include_once $dir . '/extlib/facebook.php';
return false;
case 'FacebookloginAction':
......@@ -351,26 +350,35 @@ class FacebookBridgePlugin extends Plugin
$action->script('https://connect.facebook.net/en_US/all.js');
$script = <<<ENDOFSCRIPT
FB.init({appId: %1\$s, session: %2\$s, status: true, cookie: true, xfbml: true});
function setCookie(name, value) {
var date = new Date();
date.setTime(date.getTime() + (5 * 60 * 1000)); // 5 mins
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires + "; path=/";
}
FB.init({appId: %1\$s, status: true, cookie: true, xfbml: true, oauth: true});
$('#facebook_button').bind('click', function(event) {
event.preventDefault();
FB.login(function(response) {
if (response.session && response.perms) {
window.location.href = '%3\$s';
if (response.authResponse) {
// put the access token in a cookie for the next step
setCookie('fb_access_token', response.authResponse.accessToken);
window.location.href = '%2\$s';
} else {
// NOP (user cancelled login)
}
}, {perms:'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email'});
}, {scope:'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email'});
});
ENDOFSCRIPT;
$action->inlineScript(
sprintf($script,
sprintf(
$script,
json_encode($this->facebook->getAppId()),
json_encode($this->facebook->getSession()),
common_local_url('facebookfinishlogin')
)
);
......@@ -382,26 +390,30 @@ ENDOFSCRIPT;
*
* @param Action action the current action
*/
function onEndLogout($action)
function onStartLogout($action)
{
if ($this->hasApplication()) {
$session = $this->facebook->getSession();
$fbuser = null;
$fbuid = null;
if ($session) {
try {
$fbuid = $this->facebook->getUser();
$fbuser = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
common_log(LOG_ERROR, $e, __FILE__);
}
}
if (!empty($fbuser)) {
$cur = common_current_user();
$flink = Foreign_link::getByUserID($cur->id, FACEBOOK_SERVICE);
if (!empty($flink)) {
$this->facebook->setAccessToken($flink->credentials);
if (common_config('singleuser', 'enabled')) {
$user = User::singleUser();
$destination = common_local_url(
'showstream',
array('nickname' => $user->nickname)
);
} else {
$destination = common_local_url('public');
}
$logoutUrl = $this->facebook->getLogoutUrl(
array('next' => common_local_url('public'))
array('next' => $destination)
);
common_log(
......@@ -412,9 +424,14 @@ ENDOFSCRIPT;
),
__FILE__
);
common_debug("LOGOUT URL = $logoutUrl");
$action->logout();
common_redirect($logoutUrl, 303);
return false; // probably never get here, but hey
}
return true;
}
}
......
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
* Copyright (C) 2010-2011, StatusNet, Inc.
*
* An action that handles deauthorize callbacks from Facebook
*
......@@ -23,7 +23,7 @@
* @category Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @copyright 2010-2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
......
......@@ -23,7 +23,7 @@
* @category Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @copyright 2010-2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
......@@ -72,17 +72,16 @@ class FacebookloginAction extends Action
$facebook = Facebookclient::getFacebook();
$params = array(
'scope' => 'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email',
'redirect_uri' => common_local_url('facebookfinishlogin')
);
// Degrade to plain link if JavaScript is not available
$this->elementStart(
'a',
array(
'href' => $facebook->getLoginUrl(
array(
'next' => common_local_url('facebookfinishlogin'),
'cancel' => common_local_url('facebooklogin'),
'req_perms' => 'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email'
)
),
'href' => $facebook->getLoginUrl($params),
'id' => 'facebook_button'
)
);
......@@ -99,16 +98,6 @@ class FacebookloginAction extends Action
$this->elementEnd('a');
/*
$this->element('div', array('id' => 'fb-root'));
$this->script(
sprintf(
'http://connect.facebook.net/en_US/all.js#appId=%s&xfbml=1',
common_config('facebook', 'appid')
)
);
$this->element('fb:facepile', array('max-rows' => '2', 'width' =>'300'));
*/
$this->elementEnd('fieldset');
}
......
......@@ -23,7 +23,7 @@
* @package StatusNet
* @author Craig Andrews <candrews@integralblue.com>
* @author Zach Copley <zach@status.net>
* @copyright 2009-2010 StatusNet, Inc.
* @copyright 2009-2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
......@@ -916,7 +916,7 @@ class Facebookclient
static function addFacebookUser($fbuser)
{
// remove any existing, possibly outdated, record
$luser = Foreign_user::getForeignUser($fbuser['id'], FACEBOOK_SERVICE);
$luser = Foreign_user::getForeignUser($fbuser->id, FACEBOOK_SERVICE);
if (!empty($luser)) {
......@@ -927,8 +927,8 @@ class Facebookclient
LOG_INFO,
sprintf(
'Removed old Facebook user: %s, fbuid %d',
$fbuid['name'],
$fbuid['id']
$fbuid->name,
$fbuid->id
),
__FILE__
);
......@@ -937,9 +937,9 @@ class Facebookclient
$fuser = new Foreign_user();
$fuser->nickname = $fbuser['name'];
$fuser->uri = $fbuser['link'];
$fuser->id = $fbuser['id'];
$fuser->nickname = $fbuser->username;
$fuser->uri = $fbuser->link;
$fuser->id = $fbuser->id;
$fuser->service = FACEBOOK_SERVICE;
$fuser->created = common_sql_now();
......@@ -950,8 +950,8 @@ class Facebookclient
LOG_WARNING,
sprintf(
'Failed to add new Facebook user: %s, fbuid %d',
$fbuser['name'],
$fbuser['id']
$fbuser->username,
$fbuser->id
),
__FILE__
);
......@@ -962,8 +962,8 @@ class Facebookclient
LOG_INFO,
sprintf(
'Added new Facebook user: %s, fbuid %d',
$fbuser['name'],
$fbuser['id']
$fbuser->name,
$fbuser->id
),
__FILE__
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment