3 * StatusNet, the distributed open-source microblogging tool
5 * Edit user 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/
29 if (!defined('GNUSOCIAL')) { exit(1); }
32 * Edit user settings for Facebook
36 * @author Zach Copley <zach@status.net>
37 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
38 * @link http://status.net/
42 class FacebooksettingsAction extends SettingsAction {
43 private $facebook; // Facebook PHP-SDK client obj
46 protected function doPreparation()
48 $this->facebook = new Facebook(
50 'appId' => common_config('facebook', 'appid'),
51 'secret' => common_config('facebook', 'secret'),
56 $this->flink = Foreign_link::getByUserID(
57 $this->scoped->getID(),
64 protected function doPost()
66 if ($this->arg('save')) {
67 return $this->saveSettings();
68 } else if ($this->arg('disconnect')) {
69 return $this->disconnect();
72 throw new ClientException(_('No action to take on POST.'));
76 * Returns the page title
78 * @return string page title
81 // TRANS: Page title for Facebook settings.
82 return _m('TITLE','Facebook settings');
86 * Instructions for use
88 * @return instructions for use
90 function getInstructions() {
91 // TRANS: Instructions for Facebook settings.
92 return _m('Facebook settings');
96 * Show the settings form if he/she has a link to Facebook
100 function showContent() {
101 if (!empty($this->flink)) {
107 'id' => 'form_settings_facebook',
108 'class' => 'form_settings',
109 'action' => common_local_url('facebooksettings')
113 $this->hidden('token', common_session_token());
115 // TRANS: Form note. User is connected to facebook.
116 $this->element('p', 'form_note', _m('Connected Facebook user'));
118 $this->elementStart('p', array('class' => 'facebook-user-display'));
123 'uid' => $this->flink->foreign_id,
126 'facebook-logo' => 'true'
132 array('uid' => $this->flink->foreign_id, 'useyou' => 'false')
135 $this->elementEnd('p');
137 $this->elementStart('ul', 'form_data');
139 $this->elementStart('li');
143 // TRANS: Checkbox label in Facebook settings.
144 _m('Publish my notices to Facebook.'),
145 $this->flink->noticesync & FOREIGN_NOTICE_SEND
148 $this->elementEnd('li');
150 $this->elementStart('li');
154 // TRANS: Checkbox label in Facebook settings.
155 _m('Send "@" replies to Facebook.'),
156 $this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY
159 $this->elementEnd('li');
161 $this->elementStart('li');
163 // TRANS: Submit button to save synchronisation settings.
164 $this->submit('save', _m('BUTTON', 'Save'));
166 $this->elementEnd('li');
168 $this->elementEnd('ul');
170 $this->elementStart('fieldset');
172 // TRANS: Fieldset legend for form to disconnect from Facebook.
173 $this->element('legend', null, _m('Disconnect my account from Facebook'));
175 if (!$this->scoped->hasPassword()) {
176 $this->elementStart('p', array('class' => 'form_guide'));
179 // TRANS: Notice in disconnect from Facebook form if user has no local StatusNet password.
180 _m('Disconnecting your Faceboook would make it impossible to '.
181 'log in! Please [set a password](%s) first.'),
182 common_local_url('passwordsettings')
185 $this->raw(common_markup_to_html($msg));
186 $this->elementEnd('p');
188 // @todo FIXME: i18n: This message is not being used.
189 // TRANS: Message displayed when initiating disconnect of a StatusNet user
190 // TRANS: from a Facebook account. %1$s is the StatusNet site name.
191 $msg = sprintf(_m('Keep your %1$s account but disconnect from Facebook. ' .
192 'You\'ll use your %1$s password to log in.'),
193 common_config('site', 'name')
196 // TRANS: Submit button.
197 $this->submit('disconnect', _m('BUTTON', 'Disconnect'));
200 $this->elementEnd('fieldset');
202 $this->elementEnd('form');
207 * Save the user's Facebook settings
211 function saveSettings() {
212 $noticesync = $this->boolean('noticesync');
213 $replysync = $this->boolean('replysync');
215 $original = clone($this->flink);
216 $this->flink->set_flags($noticesync, false, $replysync, false);
217 $result = $this->flink->update($original);
219 if ($result === false) {
220 // TRANS: Notice in case saving of synchronisation preferences fail.
221 throw new ServerException(_m('There was a problem saving your sync preferences.'));
223 // TRANS: Confirmation that synchronisation settings have been saved into the system.
224 return _m('Sync preferences saved.');
228 * Disconnect the user's Facebook account - deletes the Foreign_link
229 * and shows the user a success message if all goes well.
231 function disconnect() {
232 $result = $this->flink->delete();
235 if ($result === false) {
236 common_log_db_error($this->flink, 'DELETE', __FILE__);
237 // TRANS: Server error displayed when deleting the link to a Facebook account fails.
238 throw new ServerException(_m('Could not delete link to Facebook.'));
241 // TRANS: Confirmation message. GNU social account was unlinked from Facebook.
242 return _m('You have disconnected this account from Facebook.');