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('STATUSNET')) {
34 * Edit user settings for Facebook
38 * @author Zach Copley <zach@status.net>
39 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40 * @link http://status.net/
44 class FacebooksettingsAction extends SettingsAction {
45 private $facebook; // Facebook PHP-SDK client obj
50 * For initializing members of the class.
52 * @param array $argarray misc. arguments
54 * @return boolean true
56 function prepare($args) {
57 parent::prepare($args);
59 $this->facebook = new Facebook(
61 'appId' => common_config('facebook', 'appid'),
62 'secret' => common_config('facebook', 'secret'),
67 $this->user = common_current_user();
69 $this->flink = Foreign_link::getByUserID(
78 * Check the sessions token and dispatch
80 function handlePost($args) {
83 $token = $this->trimmed('token');
84 if (!$token || $token != common_session_token()) {
86 // TRANS: Client error displayed when the session token does not match or is not given.
87 _m('There was a problem with your session token. Try again, please.')
92 if ($this->arg('save')) {
93 $this->saveSettings();
94 } else if ($this->arg('disconnect')) {
100 * Returns the page title
102 * @return string page title
105 // TRANS: Page title for Facebook settings.
106 return _m('TITLE','Facebook settings');
110 * Instructions for use
112 * @return instructions for use
114 function getInstructions() {
115 // TRANS: Instructions for Facebook settings.
116 return _m('Facebook settings');
120 * Show the settings form if he/she has a link to Facebook
124 function showContent() {
125 if (!empty($this->flink)) {
131 'id' => 'form_settings_facebook',
132 'class' => 'form_settings',
133 'action' => common_local_url('facebooksettings')
137 $this->hidden('token', common_session_token());
139 // TRANS: Form note. User is connected to facebook.
140 $this->element('p', 'form_note', _m('Connected Facebook user'));
142 $this->elementStart('p', array('class' => 'facebook-user-display'));
147 'uid' => $this->flink->foreign_id,
150 'facebook-logo' => 'true'
156 array('uid' => $this->flink->foreign_id, 'useyou' => 'false')
159 $this->elementEnd('p');
161 $this->elementStart('ul', 'form_data');
163 $this->elementStart('li');
167 // TRANS: Checkbox label in Facebook settings.
168 _m('Publish my notices to Facebook.'),
169 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true
172 $this->elementEnd('li');
174 $this->elementStart('li');
178 // TRANS: Checkbox label in Facebook settings.
179 _m('Send "@" replies to Facebook.'),
180 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true
183 $this->elementEnd('li');
185 $this->elementStart('li');
187 // TRANS: Submit button to save synchronisation settings.
188 $this->submit('save', _m('BUTTON', 'Save'));
190 $this->elementEnd('li');
192 $this->elementEnd('ul');
194 $this->elementStart('fieldset');
196 // TRANS: Fieldset legend for form to disconnect from Facebook.
197 $this->element('legend', null, _m('Disconnect my account from Facebook'));
199 if (empty($this->user->password)) {
200 $this->elementStart('p', array('class' => 'form_guide'));
203 // TRANS: Notice in disconnect from Facebook form if user has no local StatusNet password.
204 _m('Disconnecting your Faceboook would make it impossible to '.
205 'log in! Please [set a password](%s) first.'),
206 common_local_url('passwordsettings')
209 $this->raw(common_markup_to_html($msg));
210 $this->elementEnd('p');
212 // @todo FIXME: i18n: This message is not being used.
213 // TRANS: Message displayed when initiating disconnect of a StatusNet user
214 // TRANS: from a Facebook account. %1$s is the StatusNet site name.
215 $msg = sprintf(_m('Keep your %1$s account but disconnect from Facebook. ' .
216 'You\'ll use your %1$s password to log in.'),
217 common_config('site', 'name')
220 // TRANS: Submit button.
221 $this->submit('disconnect', _m('BUTTON', 'Disconnect'));
224 $this->elementEnd('fieldset');
226 $this->elementEnd('form');
231 * Save the user's Facebook settings
235 function saveSettings() {
236 $noticesync = $this->boolean('noticesync');
237 $replysync = $this->boolean('replysync');
239 $original = clone($this->flink);
240 $this->flink->set_flags($noticesync, false, $replysync, false);
241 $result = $this->flink->update($original);
243 if ($result === false) {
244 // TRANS: Notice in case saving of synchronisation preferences fail.
245 $this->showForm(_m('There was a problem saving your sync preferences.'));
247 // TRANS: Confirmation that synchronisation settings have been saved into the system.
248 $this->showForm(_m('Sync preferences saved.'), true);
253 * Disconnect the user's Facebook account - deletes the Foreign_link
254 * and shows the user a success message if all goes well.
256 function disconnect() {
257 $result = $this->flink->delete();
260 if ($result === false) {
261 common_log_db_error($user, 'DELETE', __FILE__);
262 // TRANS: Server error displayed when deleting the link to a Facebook account fails.
263 $this->serverError(_m('Could not delete link to Facebook.'));
266 // TRANS: Confirmation message. StatusNet account was unlinked from Facebook.
267 $this->showForm(_m('You have disconnected from Facebook.'), true);