]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/facebooksettings.php
Update favorited for new layout and framework
[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         $prefix = $this->trimmed('prefix');
43
44         $facebook = get_facebook();
45         $fbuid = $facebook->require_login();
46
47         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
48
49         $original = clone($flink);
50         $flink->set_flags($noticesync, $replysync, false);
51         $result = $flink->update($original);
52
53         $facebook->api_client->data_setUserPreference(1, substr($prefix, 0, 128));
54
55         if ($result) {
56             $this->show_form('Sync preferences saved.', true);
57         } else {
58             $this->show_form('There was a problem saving your sync preferences!');
59         }
60     }
61
62     function show_form($msg = null, $success = false) {
63
64         $facebook = get_facebook();
65         $fbuid = $facebook->require_login();
66
67         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
68
69         $this->show_header('Settings', $msg, $success);
70
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');
76
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');
83
84         if ($facebook->api_client->users_hasAppPermission('status_update')) {
85
86             $this->elementStart('form', array('method' => 'post',
87                                                'id' => 'facebook_settings'));
88
89             $this->element('h2', null, _('Sync preferences'));
90
91             $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
92                                 ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
93
94             $this->checkbox('replysync', _('Send local "@" replies to Facebook.'),
95                              ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
96
97             // function $this->input($id, $label, $value=null,$instructions=null)
98
99             $prefix = $facebook->api_client->data_getUserPreference(1);
100             
101
102             $this->input('prefix', _('Prefix'),
103                          ($prefix) ? $prefix : null,
104                          _('A string to prefix notices with.'));
105             $this->submit('save', _('Save'));
106
107             $this->elementEnd('form');
108
109         }
110
111         $this->show_footer();
112     }
113
114 }