]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/facebooksettings.php
Merge branch 'master' of ../laconica-stable
[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
39     function save_settings() {
40
41         $noticesync = $this->arg('noticesync');
42         $replysync = $this->arg('replysync');
43
44         $facebook = get_facebook();
45         $fbuid = $facebook->require_login();
46
47         $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
48
49         $original = clone($flink);
50         $flink->set_flags($noticesync, $replysync, false);
51         $result = $flink->update($original);
52
53         if ($result) {
54             echo '<fb:success message="Sync preferences saved." />';
55         }
56
57         $this->show_form();
58
59     }
60
61     function show_form() {
62
63         $facebook = get_facebook();
64         $fbuid = $facebook->require_login();
65
66         $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
67
68         $this->show_header('Settings');
69
70         $fbml = '<fb:if-section-not-added section="profile">'
71             .'<h2>Add an Identi.ca box to my profile</h2>'
72             .'<p><fb:add-section-button section="profile"/></p>'
73             .'</fb:if-section-not-added>';
74
75         $fbml .= '<p><fb:prompt-permission perms="status_update"><h2>Allow Identi.ca to update my Facebook status</h2></fb:prompt-permission></p>';
76
77         if ($facebook->api_client->users_hasAppPermission('status_update')) {
78
79         $fbml .= '<form method="post" id="facebook_settings">'
80         .'<h2>Sync preferences</h2>'
81         .'<p>';
82
83         if ($flink->noticesync & FOREIGN_NOTICE_SEND) {
84             $fbml .= '<input name="noticesync" type="checkbox" class="checkbox" id="noticesync" checked="checked"/>';
85         } else {
86             $fbml .= '<input name="noticesync" type="checkbox" class="checkbox" id="noticesync">';
87         }
88
89         $fbml .= '<label class="checkbox_label" for="noticesync">Automatically update my Facebook status with my notices.</label>'
90         .'</p>'
91         .'<p>';
92
93         if ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) {
94             $fbml .= '<input name="replysync" type="checkbox" class="checkbox" id="replysync" checked="checked"/>';
95         } else {
96             $fbml .= '<input name="replysync" type="checkbox" class="checkbox" id="replysync"/>';
97         }
98
99         $fbml .= '<label class="checkbox_label" for="replysync">Send &quot;@&quot; replies to Facebook.</label>'
100         .'</p>'
101         .'<p>'
102         .'<input type="submit" id="save" name="save" class="submit" value="Save"/>'
103         .'</p>'
104         .'</form>';
105
106     }
107
108         echo $fbml;
109
110         $this->show_footer();
111     }
112
113 }