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 _m('There was a problem with your session token. Try again, please.')
91 if ($this->arg('save')) {
92 $this->saveSettings();
93 } else if ($this->arg('disconnect')) {
99 * Returns the page title
101 * @return string page title
104 // TRANS: Page title for Facebook settings.
105 return _m('Facebook settings');
109 * Instructions for use
111 * @return instructions for use
113 function getInstructions() {
114 return _('Facebook settings');
118 * Show the settings form if he/she has a link to Facebook
122 function showContent() {
123 if (!empty($this->flink)) {
129 'id' => 'form_settings_facebook',
130 'class' => 'form_settings',
131 'action' => common_local_url('facebooksettings')
135 $this->hidden('token', common_session_token());
137 $this->element('p', 'form_note', _m('Connected Facebook user'));
139 $this->elementStart('p', array('class' => 'facebook-user-display'));
144 'uid' => $this->flink->foreign_id,
147 'facebook-logo' => 'true'
153 array('uid' => $this->flink->foreign_id, 'useyou' => 'false')
156 $this->elementEnd('p');
158 $this->elementStart('ul', 'form_data');
160 $this->elementStart('li');
164 _m('Publish my notices to Facebook.'),
165 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true
168 $this->elementEnd('li');
170 $this->elementStart('li');
174 _m('Send "@" replies to Facebook.'),
175 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true
178 $this->elementEnd('li');
180 $this->elementStart('li');
182 // TRANS: Submit button to save synchronisation settings.
183 $this->submit('save', _m('BUTTON', 'Save'));
185 $this->elementEnd('li');
187 $this->elementEnd('ul');
189 $this->elementStart('fieldset');
192 $this->element('legend', null, _m('Disconnect my account from Facebook'));
194 if (empty($this->user->password)) {
195 $this->elementStart('p', array('class' => 'form_guide'));
199 'Disconnecting your Faceboook would make it impossible to '
200 . 'log in! Please [set a password](%s) first.'
202 common_local_url('passwordsettings')
205 $this->raw(common_markup_to_html($msg));
206 $this->elementEnd('p');
208 // @todo FIXME: i18n: This message is not being used.
210 // TRANS: Message displayed when initiating disconnect of a StatusNet user
211 // TRANS: from a Facebook account. %1$s is the StatusNet site name.
213 'Keep your %1$s account but disconnect from Facebook. ' .
214 'You\'ll use your %1$s password to log in.'
216 common_config('site', 'name')
219 // TRANS: Submit button.
220 $this->submit('disconnect', _m('BUTTON', 'Disconnect'));
223 $this->elementEnd('fieldset');
225 $this->elementEnd('form');
230 * Save the user's Facebook settings
234 function saveSettings() {
235 $noticesync = $this->boolean('noticesync');
236 $replysync = $this->boolean('replysync');
238 $original = clone($this->flink);
239 $this->flink->set_flags($noticesync, false, $replysync, false);
240 $result = $this->flink->update($original);
242 if ($result === false) {
243 $this->showForm(_m('There was a problem saving your sync preferences.'));
245 // TRANS: Confirmation that synchronisation settings have been saved into the system.
246 $this->showForm(_m('Sync preferences saved.'), true);
251 * Disconnect the user's Facebook account - deletes the Foreign_link
252 * and shows the user a success message if all goes well.
254 function disconnect() {
255 $result = $this->flink->delete();
258 if ($result === false) {
259 common_log_db_error($user, 'DELETE', __FILE__);
260 $this->serverError(_m('Couldn\'t delete link to Facebook.'));
264 $this->showForm(_m('You have disconnected from Facebook.'), true);