2009-05-21 14:43:11 +09:00
|
|
|
<?php
|
|
|
|
/**
|
2009-08-26 07:29:56 +09:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2009-05-21 14:43:11 +09:00
|
|
|
*
|
|
|
|
* Facebook Connect settings
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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 Settings
|
2009-08-26 07:29:56 +09:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @copyright 2009 StatusNet, Inc.
|
2009-05-21 14:43:11 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:29:56 +09:00
|
|
|
* @link http://status.net/
|
2009-05-21 14:43:11 +09:00
|
|
|
*/
|
|
|
|
|
2009-08-26 23:41:36 +09:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
2009-05-21 14:43:11 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once INSTALLDIR.'/lib/connectsettingsaction.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Facebook Connect settings action
|
|
|
|
*
|
|
|
|
* @category Settings
|
2009-08-26 07:29:56 +09:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
2009-05-21 14:43:11 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:29:56 +09:00
|
|
|
* @link http://status.net/
|
2009-05-21 14:43:11 +09:00
|
|
|
*/
|
|
|
|
class FBConnectSettingsAction extends ConnectSettingsAction
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
|
|
|
function title()
|
|
|
|
{
|
2010-09-19 23:32:19 +09:00
|
|
|
// TRANS: Page title.
|
2009-12-09 05:17:11 +09:00
|
|
|
return _m('Facebook Connect Settings');
|
2009-05-21 14:43:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
|
|
|
function getInstructions()
|
|
|
|
{
|
2010-09-19 23:32:19 +09:00
|
|
|
// TRANS: Instructions.
|
2009-12-09 05:17:11 +09:00
|
|
|
return _m('Manage how your account connects to Facebook');
|
2009-05-21 14:43:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content area of the page
|
|
|
|
*
|
|
|
|
* Shows a form for uploading an avatar.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showContent()
|
|
|
|
{
|
|
|
|
$user = common_current_user();
|
|
|
|
$flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
|
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->elementStart('form', array('method' => 'post',
|
|
|
|
'id' => 'form_settings_facebook',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' =>
|
|
|
|
common_local_url('FBConnectSettings')));
|
|
|
|
|
2009-05-21 14:43:11 +09:00
|
|
|
if (!$flink) {
|
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->element('p', 'instructions',
|
2009-12-09 05:17:11 +09:00
|
|
|
_m('There is no Facebook user connected to this account.'));
|
2009-05-21 14:43:11 +09:00
|
|
|
|
|
|
|
$this->element('fb:login-button', array('onlogin' => 'goto_login()',
|
|
|
|
'length' => 'long'));
|
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
} else {
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->element('p', 'form_note',
|
2009-12-09 05:17:11 +09:00
|
|
|
_m('Connected Facebook user'));
|
2009-05-28 09:08:00 +09:00
|
|
|
|
|
|
|
$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');
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->hidden('token', common_session_token());
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->elementStart('fieldset');
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2010-09-19 23:32:19 +09:00
|
|
|
// TRANS: Legend.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->element('legend', null, _m('Disconnect my account from Facebook'));
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
if (!$user->password) {
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->elementStart('p', array('class' => 'form_guide'));
|
2010-09-19 07:06:21 +09:00
|
|
|
// @todo FIXME: Bad i18n. Patchwork message in three parts.
|
|
|
|
// TRANS: Followed by a link containing text "set a password".
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->text(_m('Disconnecting your Faceboook ' .
|
|
|
|
'would make it impossible to log in! Please '));
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->element('a',
|
|
|
|
array('href' => common_local_url('passwordsettings')),
|
2010-09-19 07:06:21 +09:00
|
|
|
// TRANS: Preceded by "Please " and followed by " first."
|
2009-12-09 05:17:11 +09:00
|
|
|
_m('set a password'));
|
2010-09-19 07:06:21 +09:00
|
|
|
// TRANS: Preceded by "Please set a password".
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->text(_m(' first.'));
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->elementEnd('p');
|
|
|
|
} else {
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$note = 'Keep your %s account but disconnect from Facebook. ' .
|
|
|
|
'You\'ll use your %s password to log in.';
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$site = common_config('site', 'name');
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
$this->element('p', 'instructions',
|
|
|
|
sprintf($note, $site, $site));
|
|
|
|
|
2010-09-19 23:32:19 +09:00
|
|
|
// TRANS: Submit button.
|
|
|
|
$this->submit('disconnect', _m('BUTTON','Disconnect'));
|
2009-05-28 09:08:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
}
|
2009-05-21 14:43:11 +09:00
|
|
|
|
|
|
|
$this->elementEnd('form');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle post
|
|
|
|
*
|
|
|
|
* Disconnects the current Facebook user from the current user's account
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function handlePost()
|
|
|
|
{
|
|
|
|
// CSRF protection
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->showForm(_m('There was a problem with your session token. '.
|
|
|
|
'Try again, please.'));
|
2009-05-21 14:43:11 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->arg('disconnect')) {
|
|
|
|
|
|
|
|
$user = common_current_user();
|
|
|
|
|
|
|
|
$flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
|
|
|
|
$result = $flink->delete();
|
|
|
|
|
|
|
|
if ($result === false) {
|
|
|
|
common_log_db_error($user, 'DELETE', __FILE__);
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->serverError(_m('Couldn\'t delete link to Facebook.'));
|
2009-05-21 14:43:11 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-22 09:54:22 +09:00
|
|
|
try {
|
|
|
|
|
2009-05-28 09:08:00 +09:00
|
|
|
// Clear FB Connect cookies out
|
2009-05-22 09:54:22 +09:00
|
|
|
$facebook = getFacebook();
|
|
|
|
$facebook->clear_cookie_state();
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
2009-08-19 08:41:24 +09:00
|
|
|
common_log(LOG_WARNING, 'Facebook Connect Plugin - ' .
|
|
|
|
'Couldn\'t clear Facebook cookies: ' .
|
|
|
|
$e->getMessage());
|
2009-05-22 09:54:22 +09:00
|
|
|
}
|
2009-05-21 14:43:11 +09:00
|
|
|
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->showForm(_m('You have disconnected from Facebook.'), true);
|
2009-05-21 14:43:11 +09:00
|
|
|
|
|
|
|
} else {
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->showForm(_m('Not sure what you\'re trying to do.'));
|
2009-05-21 14:43:11 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|