3 * StatusNet, the distributed open-source microblogging tool
5 * Settings for Twitter integration
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 Evan Prodromou <evan@status.net>
25 * @copyright 2008-2009 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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR . '/lib/connectsettingsaction.php';
35 require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
38 * Settings for Twitter integration
42 * @author Evan Prodromou <evan@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
49 class TwittersettingsAction extends ConnectSettingsAction
54 * @return string Title of the page
59 return _('Twitter settings');
63 * Instructions for use
65 * @return instructions for use
68 function getInstructions()
70 return _('Connect your Twitter account to share your updates ' .
71 'with your Twitter friends and vice-versa.');
75 * Content area of the page
77 * Shows a form for associating a Twitter account with this
78 * StatusNet account. Also lets the user set preferences.
83 function showContent()
86 $user = common_current_user();
88 $profile = $user->getProfile();
92 $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
95 $fuser = $flink->getForeignUser();
98 $this->elementStart('form', array('method' => 'post',
99 'id' => 'form_settings_twitter',
100 'class' => 'form_settings',
102 common_local_url('twittersettings')));
104 $this->hidden('token', common_session_token());
106 $this->elementStart('fieldset', array('id' => 'settings_twitter_account'));
109 $this->elementStart('ul', 'form_data');
110 $this->elementStart('li', array('id' => 'settings_twitter_login_button'));
111 $this->element('a', array('href' => common_local_url('twitterauthorization')),
112 'Connect my Twitter account');
113 $this->elementEnd('li');
114 $this->elementEnd('ul');
116 $this->elementEnd('fieldset');
118 $this->element('legend', null, _('Twitter account'));
119 $this->elementStart('p', array('id' => 'form_confirmed'));
120 $this->element('a', array('href' => $fuser->uri), $fuser->nickname);
121 $this->elementEnd('p');
122 $this->element('p', 'form_note',
123 _('Connected Twitter account'));
125 $this->submit('remove', _('Remove'));
127 $this->elementEnd('fieldset');
129 $this->elementStart('fieldset', array('id' => 'settings_twitter_preferences'));
131 $this->element('legend', null, _('Preferences'));
132 $this->elementStart('ul', 'form_data');
133 $this->elementStart('li');
134 $this->checkbox('noticesend',
135 _('Automatically send my notices to Twitter.'),
137 ($flink->noticesync & FOREIGN_NOTICE_SEND) :
139 $this->elementEnd('li');
140 $this->elementStart('li');
141 $this->checkbox('replysync',
142 _('Send local "@" replies to Twitter.'),
144 ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) :
146 $this->elementEnd('li');
147 $this->elementStart('li');
148 $this->checkbox('friendsync',
149 _('Subscribe to my Twitter friends here.'),
151 ($flink->friendsync & FOREIGN_FRIEND_RECV) :
153 $this->elementEnd('li');
155 if (common_config('twitterimport','enabled')) {
156 $this->elementStart('li');
157 $this->checkbox('noticerecv',
158 _('Import my Friends Timeline.'),
160 ($flink->noticesync & FOREIGN_NOTICE_RECV) :
162 $this->elementEnd('li');
164 // preserve setting even if bidrection bridge toggled off
166 if ($flink && ($flink->noticesync & FOREIGN_NOTICE_RECV)) {
167 $this->hidden('noticerecv', true, 'noticerecv');
171 $this->elementEnd('ul');
174 $this->submit('save', _('Save'));
176 $this->submit('add', _('Add'));
179 $this->elementEnd('fieldset');
182 $this->elementEnd('form');
186 * Handle posts to this form
188 * Based on the button that was pressed, muxes out to other functions
189 * to do the actual task requested.
191 * All sub-functions reload the form with a message -- success or failure.
196 function handlePost()
199 $token = $this->trimmed('token');
200 if (!$token || $token != common_session_token()) {
201 $this->showForm(_('There was a problem with your session token. '.
202 'Try again, please.'));
206 if ($this->arg('save')) {
207 $this->savePreferences();
208 } else if ($this->arg('remove')) {
209 $this->removeTwitterAccount();
211 $this->showForm(_('Unexpected form submission.'));
216 * Disassociate an existing Twitter account from this account
221 function removeTwitterAccount()
223 $user = common_current_user();
224 $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
226 $result = $flink->delete();
228 if (empty($result)) {
229 common_log_db_error($flink, 'DELETE', __FILE__);
230 $this->serverError(_('Couldn\'t remove Twitter user.'));
234 $this->showForm(_('Twitter account removed.'), true);
238 * Save user's Twitter-bridging preferences
243 function savePreferences()
245 $noticesend = $this->boolean('noticesend');
246 $noticerecv = $this->boolean('noticerecv');
247 $friendsync = $this->boolean('friendsync');
248 $replysync = $this->boolean('replysync');
250 $user = common_current_user();
251 $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
254 common_log_db_error($flink, 'SELECT', __FILE__);
255 $this->showForm(_('Couldn\'t save Twitter preferences.'));
259 $original = clone($flink);
260 $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
261 $result = $flink->update($original);
263 if ($result === false) {
264 common_log_db_error($flink, 'UPDATE', __FILE__);
265 $this->showForm(_('Couldn\'t save Twitter preferences.'));
269 $this->showForm(_('Twitter preferences saved.'), true);