3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
22 require_once INSTALLDIR.'/lib/facebookaction.php';
24 class FacebooksettingsAction extends FacebookAction
27 function handle($args)
29 parent::handle($args);
31 if ($this->arg('save')) {
32 $this->saveSettings();
38 function saveSettings() {
40 $noticesync = $this->arg('noticesync');
41 $replysync = $this->arg('replysync');
42 $prefix = $this->trimmed('prefix');
44 $facebook = get_facebook();
45 $fbuid = $facebook->require_login();
47 $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
49 $original = clone($flink);
50 $flink->set_flags($noticesync, $replysync, false);
51 $result = $flink->update($original);
53 $facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
54 substr($prefix, 0, 128));
57 $this->showForm('Sync preferences saved.', true);
59 $this->showForm('There was a problem saving your sync preferences!');
63 function showForm($msg = null, $success = false) {
65 $facebook = get_facebook();
66 $fbuid = $facebook->require_login();
68 $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
70 $this->showHeader($msg, $success);
71 $this->showNav('Settings');
73 if ($facebook->api_client->users_hasAppPermission('status_update')) {
75 $this->elementStart('form', array('method' => 'post',
76 'id' => 'facebook_settings'));
78 $this->element('h2', null, _('Sync preferences'));
80 $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
81 ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
83 $this->checkbox('replysync', _('Send "@" replies to Facebook.'),
84 ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
86 $prefix = $facebook->api_client->data_getUserPreference(1);
88 $this->input('prefix', _('Prefix'),
89 ($prefix) ? $prefix : null,
90 _('A string to prefix notices with.'));
91 $this->submit('save', _('Save'));
93 $this->elementEnd('form');
97 // Figure what the URL of our app is.
98 $app_props = $facebook->api_client->Admin_getAppProperties(
99 array('canvas_name', 'application_name'));
100 $app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/settings.php';
101 $app_name = $app_props['application_name'];
103 $instructions = sprintf(_('If you would like the %s app to automatically update ' .
104 'your Facebook status with your latest notice, you need ' .
105 'to give it permission.'), $app_name);
107 common_element_start('p');
108 common_element('span', array('id' => 'permissions_notice'), $instructions);
109 common_element_end('p');
111 common_element_start('ul', array('id' => 'fb-permissions-list'));
112 common_element_start('li', array('id' => 'fb-permissions-item'));
113 common_element_start('fb:prompt-permission', array('perms' => 'status_update',
114 'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')'));
115 common_element('span', array('class' => 'facebook-button'),
116 _('Allow Identi.ca to update my Facebook status'));
117 common_element_end('fb:prompt-permission');
118 common_element_end('li');
119 common_element_end('ul');