3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
24 require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
26 class FacebooksettingsAction extends FacebookAction
29 function handle($args)
31 parent::handle($args);
36 * Show the page content
38 * Either shows the registration form or, if registration was successful,
39 * instructions for using the site.
44 function showContent()
46 if ($this->arg('save')) {
47 $this->saveSettings();
53 function saveSettings() {
55 $noticesync = $this->boolean('noticesync');
56 $replysync = $this->boolean('replysync');
57 $prefix = $this->trimmed('prefix');
59 $original = clone($this->flink);
60 $this->flink->set_flags($noticesync, false, $replysync, false);
61 $result = $this->flink->update($original);
63 if ($prefix == '' || $prefix == '0') {
64 // Facebook bug: saving empty strings to prefs now fails
65 // http://bugs.developers.facebook.com/show_bug.cgi?id=7110
66 $trimmed = $prefix . ' ';
68 $trimmed = substr($prefix, 0, 128);
70 $this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
73 if ($result === false) {
74 $this->showForm(_m('There was a problem saving your sync preferences!'));
76 $this->showForm(_m('Sync preferences saved.'), true);
80 function showForm($msg = null, $success = false) {
84 $this->element('fb:success', array('message' => $msg));
86 $this->element('fb:error', array('message' => $msg));
90 if ($this->facebook->api_client->users_hasAppPermission('publish_stream')) {
92 $this->elementStart('form', array('method' => 'post',
93 'id' => 'facebook_settings'));
95 $this->elementStart('ul', 'form_data');
97 $this->elementStart('li');
99 $this->checkbox('noticesync', _m('Automatically update my Facebook status with my notices.'),
100 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true);
102 $this->elementEnd('li');
104 $this->elementStart('li');
106 $this->checkbox('replysync', _m('Send "@" replies to Facebook.'),
107 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
109 $this->elementEnd('li');
111 $this->elementStart('li');
113 $prefix = trim($this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX));
115 $this->input('prefix', _m('Prefix'),
116 ($prefix) ? $prefix : null,
117 _m('A string to prefix notices with.'));
119 $this->elementEnd('li');
121 $this->elementStart('li');
123 $this->submit('save', _m('Save'));
125 $this->elementEnd('li');
127 $this->elementEnd('ul');
129 $this->elementEnd('form');
133 $instructions = sprintf(_m('If you would like %s to automatically update ' .
134 'your Facebook status with your latest notice, you need ' .
135 'to give it permission.'), $this->app_name);
137 $this->elementStart('p');
138 $this->element('span', array('id' => 'permissions_notice'), $instructions);
139 $this->elementEnd('p');
141 $this->elementStart('ul', array('id' => 'fb-permissions-list'));
142 $this->elementStart('li', array('id' => 'fb-permissions-item'));
143 $this->elementStart('fb:prompt-permission', array('perms' => 'publish_stream',
144 'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')'));
145 $this->element('span', array('class' => 'facebook-button'),
146 sprintf(_m('Allow %s to update my Facebook status'), common_config('site', 'name')));
147 $this->elementEnd('fb:prompt-permission');
148 $this->elementEnd('li');
149 $this->elementEnd('ul');
156 return _m('Sync preferences');