3 * StatusNet, the distributed open-source microblogging tool
5 * Facebook Connect settings
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/connectsettingsaction.php';
37 * Facebook Connect settings action
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class FBConnectSettingsAction extends ConnectSettingsAction
51 * @return string Title of the page
56 return _m('Facebook Connect Settings');
60 * Instructions for use
62 * @return instructions for use
65 function getInstructions()
67 return _m('Manage how your account connects to Facebook');
71 * Content area of the page
73 * Shows a form for uploading an avatar.
78 function showContent()
80 $user = common_current_user();
81 $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
83 $this->elementStart('form', array('method' => 'post',
84 'id' => 'form_settings_facebook',
85 'class' => 'form_settings',
87 common_local_url('FBConnectSettings')));
91 $this->element('p', 'instructions',
92 _m('There is no Facebook user connected to this account.'));
94 $this->element('fb:login-button', array('onlogin' => 'goto_login()',
99 $this->element('p', 'form_note',
100 _m('Connected Facebook user'));
102 $this->elementStart('p', array('class' => 'facebook-user-display'));
103 $this->elementStart('fb:profile-pic',
104 array('uid' => $flink->foreign_id,
107 'facebook-logo' => 'true'));
108 $this->elementEnd('fb:profile-pic');
110 $this->elementStart('fb:name', array('uid' => $flink->foreign_id,
111 'useyou' => 'false'));
112 $this->elementEnd('fb:name');
113 $this->elementEnd('p');
115 $this->hidden('token', common_session_token());
117 $this->elementStart('fieldset');
119 $this->element('legend', null, _m('Disconnect my account from Facebook'));
121 if (!$user->password) {
123 $this->elementStart('p', array('class' => 'form_guide'));
124 // @todo FIXME: Bad i18n. Patchwork message in three parts.
125 // TRANS: Followed by a link containing text "set a password".
126 $this->text(_m('Disconnecting your Faceboook ' .
127 'would make it impossible to log in! Please '));
129 array('href' => common_local_url('passwordsettings')),
130 // TRANS: Preceded by "Please " and followed by " first."
131 _m('set a password'));
132 // TRANS: Preceded by "Please set a password".
133 $this->text(_m(' first.'));
134 $this->elementEnd('p');
137 $note = 'Keep your %s account but disconnect from Facebook. ' .
138 'You\'ll use your %s password to log in.';
140 $site = common_config('site', 'name');
142 $this->element('p', 'instructions',
143 sprintf($note, $site, $site));
145 $this->submit('disconnect', _m('Disconnect'));
148 $this->elementEnd('fieldset');
151 $this->elementEnd('form');
157 * Disconnects the current Facebook user from the current user's account
162 function handlePost()
165 $token = $this->trimmed('token');
166 if (!$token || $token != common_session_token()) {
167 $this->showForm(_m('There was a problem with your session token. '.
168 'Try again, please.'));
172 if ($this->arg('disconnect')) {
174 $user = common_current_user();
176 $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
177 $result = $flink->delete();
179 if ($result === false) {
180 common_log_db_error($user, 'DELETE', __FILE__);
181 $this->serverError(_m('Couldn\'t delete link to Facebook.'));
187 // Clear FB Connect cookies out
188 $facebook = getFacebook();
189 $facebook->clear_cookie_state();
191 } catch (Exception $e) {
192 common_log(LOG_WARNING, 'Facebook Connect Plugin - ' .
193 'Couldn\'t clear Facebook cookies: ' .
197 $this->showForm(_m('You have disconnected from Facebook.'), true);
200 $this->showForm(_m('Not sure what you\'re trying to do.'));