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
47 protected function doPreparation()
49 $this->facebook = new Facebook(
51 'appId' => common_config('facebook', 'appid'),
52 'secret' => common_config('facebook', 'secret'),
57 $this->flink = Foreign_link::getByUserID(
58 $this->scoped->getID(),
63 protected function doPost()
65 if ($this->arg('save')) {
66 return $this->saveSettings();
67 } else if ($this->arg('disconnect')) {
68 return $this->disconnect();
71 throw new ClientException(_('No action to take on POST.'));
75 * Returns the page title
77 * @return string page title
80 // TRANS: Page title for Facebook settings.
81 return _m('TITLE','Facebook settings');
85 * Instructions for use
87 * @return instructions for use
89 function getInstructions() {
90 // TRANS: Instructions for Facebook settings.
91 return _m('Facebook settings');
95 * Show the settings form if he/she has a link to Facebook
99 function showContent() {
100 if (!$this->flink instanceof Foreign_link) {
101 throw new ServerException(_m('You have not linked this account to Facebook.'));
108 'id' => 'form_settings_facebook',
109 'class' => 'form_settings',
110 'action' => common_local_url('facebooksettings')
114 $this->hidden('token', common_session_token());
116 // TRANS: Form note. User is connected to facebook.
117 $this->element('p', 'form_note', _m('Connected Facebook user'));
119 $this->elementStart('p', array('class' => 'facebook-user-display'));
124 'uid' => $this->flink->foreign_id,
127 'facebook-logo' => 'true'
133 array('uid' => $this->flink->foreign_id, 'useyou' => 'false')
136 $this->elementEnd('p');
138 $this->elementStart('ul', 'form_data');
140 $this->elementStart('li');
144 // TRANS: Checkbox label in Facebook settings.
145 _m('Publish my notices to Facebook.'),
146 $this->flink->noticesync & FOREIGN_NOTICE_SEND
149 $this->elementEnd('li');
151 $this->elementStart('li');
155 // TRANS: Checkbox label in Facebook settings.
156 _m('Send "@" replies to Facebook.'),
157 $this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY
160 $this->elementEnd('li');
162 $this->elementStart('li');
164 // TRANS: Submit button to save synchronisation settings.
165 $this->submit('save', _m('BUTTON', 'Save'));
167 $this->elementEnd('li');
169 $this->elementEnd('ul');
171 $this->elementStart('fieldset');
173 // TRANS: Fieldset legend for form to disconnect from Facebook.
174 $this->element('legend', null, _m('Disconnect my account from Facebook'));
176 if (!$this->scoped->hasPassword()) {
177 $this->elementStart('p', array('class' => 'form_guide'));
180 // TRANS: Notice in disconnect from Facebook form if user has no local StatusNet password.
181 _m('Disconnecting your Faceboook would make it impossible to '.
182 'log in! Please [set a password](%s) first.'),
183 common_local_url('passwordsettings')
186 $this->raw(common_markup_to_html($msg));
187 $this->elementEnd('p');
189 // @todo FIXME: i18n: This message is not being used.
190 // TRANS: Message displayed when initiating disconnect of a StatusNet user
191 // TRANS: from a Facebook account. %1$s is the StatusNet site name.
192 $msg = sprintf(_m('Keep your %1$s account but disconnect from Facebook. ' .
193 'You\'ll use your %1$s password to log in.'),
194 common_config('site', 'name')
197 // TRANS: Submit button.
198 $this->submit('disconnect', _m('BUTTON', 'Disconnect'));
201 $this->elementEnd('fieldset');
203 $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.');