3 * StatusNet, the distributed open-source microblogging tool
5 * Settings for Facebook
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 2010 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')) {
35 * Settings for Facebook
39 * @author Zach Copley <zach@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
46 class FacebooksettingsAction extends ConnectSettingsAction
52 function prepare($args)
54 parent::prepare($args);
56 $this->facebook = new Facebook(
58 'appId' => common_config('facebook', 'appid'),
59 'secret' => common_config('facebook', 'secret'),
64 $this->user = common_current_user();
65 $this->flink = Foreign_link::getByUserID($this->user->id, FACEBOOK_SERVICE);
70 function handlePost($args)
74 $token = $this->trimmed('token');
75 if (!$token || $token != common_session_token()) {
77 _m('There was a problem with your session token. Try again, please.')
82 if ($this->arg('save')) {
83 $this->saveSettings();
84 } else if ($this->arg('disconnect')) {
91 // TRANS: Page title for Facebook settings.
92 return _m('Facebook settings');
96 * Instructions for use
98 * @return instructions for use
101 function getInstructions()
103 return _('Facebook settings');
106 function showContent()
109 if (empty($this->flink)) {
114 _m('There is no Facebook user connected to this account.')
118 'show-faces' => 'true',
119 'perms' => 'user_location,user_website,offline_access,publish_stream'
122 $this->element('fb:login-button', $attrs);
131 'id' => 'form_settings_facebook',
132 'class' => 'form_settings',
133 'action' => common_local_url('facebooksettings')
137 $this->hidden('token', common_session_token());
139 $this->element('p', 'form_note', _m('Connected Facebook user'));
141 $this->elementStart('p', array('class' => 'facebook-user-display'));
145 array('uid' => $this->flink->foreign_id,
148 'facebook-logo' => 'true')
150 $this->elementEnd('fb:profile-pic');
154 array('uid' => $this->flink->foreign_id, 'useyou' => 'false')
157 $this->elementEnd('fb:name');
159 $this->elementEnd('p');
161 $this->elementStart('ul', 'form_data');
163 $this->elementStart('li');
167 _m('Publish my notices to Facebook.'),
168 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true
171 $this->elementEnd('li');
173 $this->elementStart('li');
177 _m('Send "@" replies to Facebook.'),
178 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true
181 $this->elementEnd('li');
183 $this->elementStart('li');
185 // TRANS: Submit button to save synchronisation settings.
186 $this->submit('save', _m('BUTTON','Save'));
188 $this->elementEnd('li');
190 $this->elementEnd('ul');
192 $this->elementStart('fieldset');
195 $this->element('legend', null, _m('Disconnect my account from Facebook'));
197 if (empty($this->user->password)) {
199 $this->elementStart('p', array('class' => 'form_guide'));
200 // @todo FIXME: Bad i18n. Patchwork message in three parts.
201 // TRANS: Followed by a link containing text "set a password".
202 $this->text(_m('Disconnecting your Faceboook ' .
203 'would make it impossible to log in! Please '));
205 array('href' => common_local_url('passwordsettings')),
206 // TRANS: Preceded by "Please " and followed by " first."
207 _m('set a password'));
208 // TRANS: Preceded by "Please set a password".
209 $this->text(_m(' first.'));
210 $this->elementEnd('p');
213 $note = 'Keep your %s account but disconnect from Facebook. ' .
214 'You\'ll use your %s password to log in.';
216 $site = common_config('site', 'name');
218 $this->element('p', 'instructions',
219 sprintf($note, $site, $site));
221 // TRANS: Submit button.
222 $this->submit('disconnect', _m('BUTTON','Disconnect'));
225 $this->elementEnd('fieldset');
227 $this->elementEnd('form');
231 function saveSettings()
234 $noticesync = $this->boolean('noticesync');
235 $replysync = $this->boolean('replysync');
237 $original = clone($this->flink);
238 $this->flink->set_flags($noticesync, false, $replysync, false);
239 $result = $this->flink->update($original);
241 if ($result === false) {
242 $this->showForm(_m('There was a problem saving your sync preferences.'));
244 // TRANS: Confirmation that synchronisation settings have been saved into the system.
245 $this->showForm(_m('Sync preferences saved.'), true);
249 function disconnect()
251 $flink = Foreign_link::getByUserID($this->user->id, FACEBOOK_SERVICE);
252 $result = $flink->delete();
254 if ($result === false) {
255 common_log_db_error($user, 'DELETE', __FILE__);
256 $this->serverError(_m('Couldn\'t delete link to Facebook.'));
260 $this->showForm(_m('You have disconnected from Facebook.'), true);