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->save_settings();
38 function save_settings() {
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(1, substr($prefix, 0, 128));
56 $this->show_form('Sync preferences saved.', true);
58 $this->show_form('There was a problem saving your sync preferences!');
62 function show_form($msg = null, $success = false) {
64 $facebook = get_facebook();
65 $fbuid = $facebook->require_login();
67 $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
69 $this->show_header('Settings', $msg, $success);
71 $this->elementStart('fb:if-section-not-added', array('section' => 'profile'));
72 $this->element('h2', null, _('Add an Identi.ca box to my profile'));
73 $this->elementStart('p');
74 $this->element('fb:add-section-button', array('section' => 'profile'));
75 $this->elementEnd('p');
77 $this->elementEnd('fb:if-section-not-added');
78 $this->elementStart('p');
79 $this->elementStart('fb:prompt-permission', array('perms' => 'status_update'));
80 $this->element('h2', null, _('Allow Identi.ca to update my Facebook status'));
81 $this->elementEnd('fb:prompt-permission');
82 $this->elementEnd('p');
84 if ($facebook->api_client->users_hasAppPermission('status_update')) {
86 $this->elementStart('form', array('method' => 'post',
87 'id' => 'facebook_settings'));
89 $this->element('h2', null, _('Sync preferences'));
91 $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
92 ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
94 $this->checkbox('replysync', _('Send local "@" replies to Facebook.'),
95 ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
97 // function $this->input($id, $label, $value=null,$instructions=null)
99 $prefix = $facebook->api_client->data_getUserPreference(1);
102 $this->input('prefix', _('Prefix'),
103 ($prefix) ? $prefix : null,
104 _('A string to prefix notices with.'));
105 $this->submit('save', _('Save'));
107 $this->elementEnd('form');
111 $this->show_footer();