]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/facebooksettings.php
Fix for ticket 2756 - Calls to OAuth endpoints are redirected to the
[quix0rs-gnu-social.git] / plugins / Facebook / facebooksettings.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, 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('STATUSNET') && !defined('LACONICA')) {
21     exit(1);
22 }
23
24 require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
25
26 class FacebooksettingsAction extends FacebookAction
27 {
28
29     function handle($args)
30     {
31         parent::handle($args);
32         $this->showPage();
33     }
34
35     /**
36      * Show the page content
37      *
38      * Either shows the registration form or, if registration was successful,
39      * instructions for using the site.
40      *
41      * @return void
42      */
43
44     function showContent()
45     {
46         if ($this->arg('save')) {
47             $this->saveSettings();
48         } else {
49             $this->showForm();
50         }
51     }
52
53     function saveSettings() {
54
55         $noticesync = $this->boolean('noticesync');
56         $replysync  = $this->boolean('replysync');
57
58         $original = clone($this->flink);
59         $this->flink->set_flags($noticesync, false, $replysync, false);
60         $result = $this->flink->update($original);
61
62         if ($result === false) {
63             $this->showForm(_m('There was a problem saving your sync preferences!'));
64         } else {
65             $this->showForm(_m('Sync preferences saved.'), true);
66         }
67     }
68
69     function showForm($msg = null, $success = false) {
70
71         if ($msg) {
72             if ($success) {
73                 $this->element('fb:success', array('message' => $msg));
74             } else {
75                 $this->element('fb:error', array('message' => $msg));
76             }
77         }
78
79         if ($this->facebook->api_client->users_hasAppPermission('publish_stream')) {
80
81             $this->elementStart('form', array('method' => 'post',
82                                                'id' => 'facebook_settings'));
83
84             $this->elementStart('ul', 'form_data');
85
86             $this->elementStart('li');
87
88             $this->checkbox('noticesync', _m('Automatically update my Facebook status with my notices.'),
89                                 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true);
90
91             $this->elementEnd('li');
92
93             $this->elementStart('li');
94
95             $this->checkbox('replysync', _m('Send "@" replies to Facebook.'),
96                              ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
97
98             $this->elementEnd('li');
99
100             $this->elementStart('li');
101
102             $this->submit('save', _m('Save'));
103
104             $this->elementEnd('li');
105
106             $this->elementEnd('ul');
107
108             $this->elementEnd('form');
109
110         } else {
111
112             $instructions = sprintf(_m('If you would like %s to automatically update ' .
113                 'your Facebook status with your latest notice, you need ' .
114                 'to give it permission.'), $this->app_name);
115
116             $this->elementStart('p');
117             $this->element('span', array('id' => 'permissions_notice'), $instructions);
118             $this->elementEnd('p');
119
120             $this->elementStart('ul', array('id' => 'fb-permissions-list'));
121             $this->elementStart('li', array('id' => 'fb-permissions-item'));
122             $this->elementStart('fb:prompt-permission', array('perms' => 'publish_stream',
123                 'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')'));
124             $this->element('span', array('class' => 'facebook-button'),
125                 sprintf(_m('Allow %s to update my Facebook status'), common_config('site', 'name')));
126             $this->elementEnd('fb:prompt-permission');
127             $this->elementEnd('li');
128             $this->elementEnd('ul');
129         }
130
131     }
132
133     function title()
134     {
135         return _m('Sync preferences');
136     }
137
138 }