2010-11-02 10:41:31 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
2010-11-18 06:53:56 +09:00
|
|
|
* Edit user settings for Facebook
|
2010-11-02 10:41:31 +09:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @copyright 2010 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/
|
|
|
|
*/
|
2015-07-17 22:24:37 +09:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2010-11-02 10:41:31 +09:00
|
|
|
|
|
|
|
/**
|
2010-11-18 06:53:56 +09:00
|
|
|
* Edit user settings for Facebook
|
2010-11-02 10:41:31 +09:00
|
|
|
*
|
|
|
|
* @category Settings
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*
|
|
|
|
* @see SettingsAction
|
|
|
|
*/
|
2011-01-24 02:35:35 +09:00
|
|
|
class FacebooksettingsAction extends SettingsAction {
|
2010-11-18 06:53:56 +09:00
|
|
|
private $facebook; // Facebook PHP-SDK client obj
|
2015-07-17 22:27:47 +09:00
|
|
|
|
|
|
|
protected $flink;
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:24:37 +09:00
|
|
|
protected function doPreparation()
|
|
|
|
{
|
2010-11-02 10:41:31 +09:00
|
|
|
$this->facebook = new Facebook(
|
|
|
|
array(
|
|
|
|
'appId' => common_config('facebook', 'appid'),
|
|
|
|
'secret' => common_config('facebook', 'secret'),
|
|
|
|
'cookie' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2010-11-18 06:53:56 +09:00
|
|
|
$this->flink = Foreign_link::getByUserID(
|
2015-07-17 22:24:37 +09:00
|
|
|
$this->scoped->getID(),
|
2010-11-18 06:53:56 +09:00
|
|
|
FACEBOOK_SERVICE
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
|
|
|
|
2015-07-17 22:24:37 +09:00
|
|
|
protected function doPost()
|
|
|
|
{
|
2010-11-02 10:41:31 +09:00
|
|
|
if ($this->arg('save')) {
|
2015-07-17 22:24:37 +09:00
|
|
|
return $this->saveSettings();
|
2010-11-02 10:41:31 +09:00
|
|
|
} else if ($this->arg('disconnect')) {
|
2015-07-17 22:24:37 +09:00
|
|
|
return $this->disconnect();
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
2015-07-17 22:24:37 +09:00
|
|
|
|
|
|
|
throw new ClientException(_('No action to take on POST.'));
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
|
|
|
|
2010-11-18 06:53:56 +09:00
|
|
|
/**
|
|
|
|
* Returns the page title
|
|
|
|
*
|
|
|
|
* @return string page title
|
|
|
|
*/
|
|
|
|
function title() {
|
2010-11-02 10:41:31 +09:00
|
|
|
// TRANS: Page title for Facebook settings.
|
2011-04-08 17:59:10 +09:00
|
|
|
return _m('TITLE','Facebook settings');
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
2010-11-18 06:53:56 +09:00
|
|
|
|
2010-11-02 10:41:31 +09:00
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
2010-11-18 06:53:56 +09:00
|
|
|
function getInstructions() {
|
2011-04-08 17:59:10 +09:00
|
|
|
// TRANS: Instructions for Facebook settings.
|
2011-03-31 05:30:23 +09:00
|
|
|
return _m('Facebook settings');
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
|
|
|
|
2010-11-18 06:53:56 +09:00
|
|
|
/*
|
|
|
|
* Show the settings form if he/she has a link to Facebook
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showContent() {
|
2015-07-17 22:27:47 +09:00
|
|
|
if (!$this->flink instanceof Foreign_link) {
|
|
|
|
throw new ServerException(_m('You have not linked this account to Facebook.'));
|
|
|
|
}
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementStart(
|
|
|
|
'form',
|
|
|
|
array(
|
|
|
|
'method' => 'post',
|
|
|
|
'id' => 'form_settings_facebook',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' => common_local_url('facebooksettings')
|
|
|
|
)
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->hidden('token', common_session_token());
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
// TRANS: Form note. User is connected to facebook.
|
|
|
|
$this->element('p', 'form_note', _m('Connected Facebook user'));
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementStart('p', array('class' => 'facebook-user-display'));
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->element(
|
|
|
|
'fb:profile-pic',
|
|
|
|
array(
|
|
|
|
'uid' => $this->flink->foreign_id,
|
|
|
|
'size' => 'small',
|
|
|
|
'linked' => 'true',
|
|
|
|
'facebook-logo' => 'true'
|
|
|
|
)
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->element(
|
|
|
|
'fb:name',
|
|
|
|
array('uid' => $this->flink->foreign_id, 'useyou' => 'false')
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementEnd('p');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementStart('ul', 'form_data');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementStart('li');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->checkbox(
|
|
|
|
'noticesync',
|
|
|
|
// TRANS: Checkbox label in Facebook settings.
|
|
|
|
_m('Publish my notices to Facebook.'),
|
|
|
|
$this->flink->noticesync & FOREIGN_NOTICE_SEND
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementEnd('li');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementStart('li');
|
|
|
|
|
|
|
|
$this->checkbox(
|
|
|
|
'replysync',
|
|
|
|
// TRANS: Checkbox label in Facebook settings.
|
|
|
|
_m('Send "@" replies to Facebook.'),
|
|
|
|
$this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementEnd('li');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementStart('li');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
// TRANS: Submit button to save synchronisation settings.
|
|
|
|
$this->submit('save', _m('BUTTON', 'Save'));
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementEnd('li');
|
2010-11-18 06:53:56 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementEnd('ul');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementStart('fieldset');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
// TRANS: Fieldset legend for form to disconnect from Facebook.
|
|
|
|
$this->element('legend', null, _m('Disconnect my account from Facebook'));
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
if (!$this->scoped->hasPassword()) {
|
|
|
|
$this->elementStart('p', array('class' => 'form_guide'));
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$msg = sprintf(
|
|
|
|
// TRANS: Notice in disconnect from Facebook form if user has no local StatusNet password.
|
|
|
|
_m('Disconnecting your Faceboook would make it impossible to '.
|
|
|
|
'log in! Please [set a password](%s) first.'),
|
|
|
|
common_local_url('passwordsettings')
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->raw(common_markup_to_html($msg));
|
|
|
|
$this->elementEnd('p');
|
|
|
|
} else {
|
|
|
|
// @todo FIXME: i18n: This message is not being used.
|
|
|
|
// TRANS: Message displayed when initiating disconnect of a StatusNet user
|
|
|
|
// TRANS: from a Facebook account. %1$s is the StatusNet site name.
|
|
|
|
$msg = sprintf(_m('Keep your %1$s account but disconnect from Facebook. ' .
|
|
|
|
'You\'ll use your %1$s password to log in.'),
|
|
|
|
common_config('site', 'name')
|
|
|
|
);
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
// TRANS: Submit button.
|
|
|
|
$this->submit('disconnect', _m('BUTTON', 'Disconnect'));
|
|
|
|
}
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementEnd('fieldset');
|
2010-11-02 10:41:31 +09:00
|
|
|
|
2015-07-17 22:27:47 +09:00
|
|
|
$this->elementEnd('form');
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
|
|
|
|
2010-11-18 06:53:56 +09:00
|
|
|
/*
|
|
|
|
* Save the user's Facebook settings
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function saveSettings() {
|
2010-11-02 10:41:31 +09:00
|
|
|
$noticesync = $this->boolean('noticesync');
|
|
|
|
$replysync = $this->boolean('replysync');
|
|
|
|
|
|
|
|
$original = clone($this->flink);
|
|
|
|
$this->flink->set_flags($noticesync, false, $replysync, false);
|
|
|
|
$result = $this->flink->update($original);
|
|
|
|
|
|
|
|
if ($result === false) {
|
2011-04-08 17:59:10 +09:00
|
|
|
// TRANS: Notice in case saving of synchronisation preferences fail.
|
2015-07-17 22:24:37 +09:00
|
|
|
throw new ServerException(_m('There was a problem saving your sync preferences.'));
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
2015-07-17 22:24:37 +09:00
|
|
|
// TRANS: Confirmation that synchronisation settings have been saved into the system.
|
|
|
|
return _m('Sync preferences saved.');
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
|
|
|
|
2010-11-18 06:53:56 +09:00
|
|
|
/*
|
|
|
|
* Disconnect the user's Facebook account - deletes the Foreign_link
|
|
|
|
* and shows the user a success message if all goes well.
|
|
|
|
*/
|
|
|
|
function disconnect() {
|
|
|
|
$result = $this->flink->delete();
|
|
|
|
$this->flink = null;
|
2010-11-02 10:41:31 +09:00
|
|
|
|
|
|
|
if ($result === false) {
|
2015-07-17 22:24:37 +09:00
|
|
|
common_log_db_error($this->flink, 'DELETE', __FILE__);
|
2011-04-08 17:59:10 +09:00
|
|
|
// TRANS: Server error displayed when deleting the link to a Facebook account fails.
|
2015-07-17 22:24:37 +09:00
|
|
|
throw new ServerException(_m('Could not delete link to Facebook.'));
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
|
|
|
|
2015-07-17 22:24:37 +09:00
|
|
|
// TRANS: Confirmation message. GNU social account was unlinked from Facebook.
|
|
|
|
return _m('You have disconnected this account from Facebook.');
|
2010-11-02 10:41:31 +09:00
|
|
|
}
|
2010-11-18 06:53:56 +09:00
|
|
|
}
|