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')) { exit(1); }
22 require_once INSTALLDIR.'/lib/facebookaction.php';
24 class FacebooksettingsAction extends FacebookAction
27 function handle($args)
29 parent::handle($args);
34 * Show the page content
36 * Either shows the registration form or, if registration was successful,
37 * instructions for using the site.
42 function showContent()
44 if ($this->arg('save')) {
45 $this->saveSettings();
51 function saveSettings() {
53 $noticesync = $this->arg('noticesync');
54 $replysync = $this->arg('replysync');
55 $prefix = $this->trimmed('prefix');
57 $original = clone($this->flink);
58 $this->flink->set_flags($noticesync, $replysync, false, false);
59 $result = $this->flink->update($original);
61 $this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
62 substr($prefix, 0, 128));
64 if ($result === false) {
65 $this->showForm(_('There was a problem saving your sync preferences!'));
67 $this->showForm(_('Sync preferences saved.'), true);
71 function showForm($msg = null, $success = false) {
75 $this->element('fb:success', array('message' => $msg));
77 $this->element('fb:error', array('message' => $msg));
81 if ($this->facebook->api_client->users_hasAppPermission('publish_stream')) {
83 $this->elementStart('form', array('method' => 'post',
84 'id' => 'facebook_settings'));
86 $this->elementStart('ul', 'form_data');
88 $this->elementStart('li');
90 $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
91 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true);
93 $this->elementEnd('li');
95 $this->elementStart('li');
97 $this->checkbox('replysync', _('Send "@" replies to Facebook.'),
98 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
100 $this->elementEnd('li');
102 $this->elementStart('li');
104 $prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX);
106 $this->input('prefix', _('Prefix'),
107 ($prefix) ? $prefix : null,
108 _('A string to prefix notices with.'));
110 $this->elementEnd('li');
112 $this->elementStart('li');
114 $this->submit('save', _('Save'));
116 $this->elementEnd('li');
118 $this->elementEnd('ul');
120 $this->elementEnd('form');
124 $instructions = sprintf(_('If you would like %s to automatically update ' .
125 'your Facebook status with your latest notice, you need ' .
126 'to give it permission.'), $this->app_name);
128 $this->elementStart('p');
129 $this->element('span', array('id' => 'permissions_notice'), $instructions);
130 $this->elementEnd('p');
132 $this->elementStart('ul', array('id' => 'fb-permissions-list'));
133 $this->elementStart('li', array('id' => 'fb-permissions-item'));
134 $this->elementStart('fb:prompt-permission', array('perms' => 'publish_stream',
135 'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')'));
136 $this->element('span', array('class' => 'facebook-button'),
137 sprintf(_('Allow %s to update my Facebook status'), common_config('site', 'name')));
138 $this->elementEnd('fb:prompt-permission');
139 $this->elementEnd('li');
140 $this->elementEnd('ul');
147 return _('Sync preferences');