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 ConnectSettingsAction {
46 private $facebook; // Facebook PHP-SDK client obj
51 * For initializing members of the class.
53 * @param array $argarray misc. arguments
55 * @return boolean true
57 function prepare($args) {
58 parent::prepare($args);
60 $this->facebook = new Facebook(
62 'appId' => common_config('facebook', 'appid'),
63 'secret' => common_config('facebook', 'secret'),
68 $this->user = common_current_user();
70 $this->flink = Foreign_link::getByUserID(
79 * Check the sessions token and dispatch
81 function handlePost($args) {
84 $token = $this->trimmed('token');
85 if (!$token || $token != common_session_token()) {
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('Facebook settings');
110 * Instructions for use
112 * @return instructions for use
114 function getInstructions() {
115 return _('Facebook settings');
119 * Show the settings form if he/she has a link to Facebook
123 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 $this->element('p', 'form_note', _m('Connected Facebook user'));
141 $this->elementStart('p', array('class' => 'facebook-user-display'));
146 'uid' => $this->flink->foreign_id,
149 'facebook-logo' => 'true'
155 array('uid' => $this->flink->foreign_id, 'useyou' => 'false')
158 $this->elementEnd('p');
160 $this->elementStart('ul', 'form_data');
162 $this->elementStart('li');
166 _m('Publish my notices to Facebook.'),
167 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true
170 $this->elementEnd('li');
172 $this->elementStart('li');
176 _m('Send "@" replies to Facebook.'),
177 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true
180 $this->elementEnd('li');
182 $this->elementStart('li');
184 // TRANS: Submit button to save synchronisation settings.
185 $this->submit('save', _m('BUTTON', 'Save'));
187 $this->elementEnd('li');
189 $this->elementEnd('ul');
191 $this->elementStart('fieldset');
194 $this->element('legend', null, _m('Disconnect my account from Facebook'));
196 if (empty($this->user->password)) {
198 $this->elementStart('p', array('class' => 'form_guide'));
202 'Disconnecting your Faceboook would make it impossible to '
203 . 'log in! Please [set a password](%s) first.'
205 common_local_url('passwordsettings')
208 $this->raw(common_markup_to_html($msg));
209 $this->elementEnd('p');
215 'Keep your %1$s account but disconnect from Facebook. ' .
216 'You\'ll use your 1%$s password to log in.'
218 common_config('site', 'name')
221 // TRANS: Submit button.
222 $this->submit('disconnect', _m('BUTTON', 'Disconnect'));
225 $this->elementEnd('fieldset');
227 $this->elementEnd('form');
232 * Save the user's Facebook settings
236 function saveSettings() {
238 $noticesync = $this->boolean('noticesync');
239 $replysync = $this->boolean('replysync');
241 $original = clone($this->flink);
242 $this->flink->set_flags($noticesync, false, $replysync, false);
243 $result = $this->flink->update($original);
245 if ($result === false) {
246 $this->showForm(_m('There was a problem saving your sync preferences.'));
248 // TRANS: Confirmation that synchronisation settings have been saved into the system.
249 $this->showForm(_m('Sync preferences saved.'), true);
254 * Disconnect the user's Facebook account - deletes the Foreign_link
255 * and shows the user a success message if all goes well.
257 function disconnect() {
259 $result = $this->flink->delete();
262 if ($result === false) {
263 common_log_db_error($user, 'DELETE', __FILE__);
264 $this->serverError(_m('Couldn\'t delete link to Facebook.'));
268 $this->showForm(_m('You have disconnected from Facebook.'), true);