]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/facebooksettings.php
trac750 Automatically update Identi.ca profile box with user's latest dent
[quix0rs-gnu-social.git] / actions / facebooksettings.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/facebookaction.php');
23
24 class FacebooksettingsAction extends FacebookAction
25 {
26
27     function handle($args)
28     {
29         parent::handle($args);
30
31         if ($this->arg('save')) {
32             $this->save_settings();
33         } else {
34             $this->show_form();
35         }
36     }
37
38     function save_settings() {
39
40         $noticesync = $this->arg('noticesync');
41         $replysync = $this->arg('replysync');
42
43         $facebook = get_facebook();
44         $fbuid = $facebook->require_login();
45
46         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
47
48         $original = clone($flink);
49         $flink->set_flags($noticesync, $replysync, false);
50         $result = $flink->update($original);
51
52         if ($result) {
53             $this->show_form('Sync preferences saved.', true);
54         } else {
55             $this->show_form('There was a problem saving your sync preferences!');
56         }
57     }
58
59     function show_form($msg = null, $success = false) {
60
61         $facebook = get_facebook();
62         $fbuid = $facebook->require_login();
63
64         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
65
66         $this->show_header('Settings', $msg, $success);
67
68         common_element_start('fb:if-section-not-added', array('section' => 'profile'));
69         common_element('h2', null, _('Add an Identi.ca box to my profile'));
70         common_element_start('p');
71         common_element('fb:add-section-button', array('section' => 'profile'));
72         common_element_end('p');
73         common_element_end('fb:if-section-not-added');
74
75         common_element_start('p');
76         common_element_start('fb:prompt-permission', array('perms' => 'status_update'));
77         common_element('h2', null, _('Allow Identi.ca to update my Facebook status'));
78         common_element_end('fb:prompt-permission');
79         common_element_end('p');
80
81         if ($facebook->api_client->users_hasAppPermission('status_update')) {
82
83             common_element_start('form', array('method' => 'post',
84                                                'id' => 'facebook_settings'));
85
86             common_element('h2', null, _('Sync preferences'));
87
88             common_checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
89                                 ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
90
91             common_checkbox('replysync', _('Send local "@" replies to Facebook.'),
92                              ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
93
94             common_submit('save', _('Save'));
95
96             common_element_end('form');
97
98         }
99
100         $this->show_footer();
101     }
102
103 }