]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/FBConnectSettings.php
Remove superfluous whitespace.
[quix0rs-gnu-social.git] / plugins / Facebook / FBConnectSettings.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Facebook Connect settings
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/connectsettingsaction.php';
35
36 /**
37  * Facebook Connect settings action
38  *
39  * @category Settings
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45
46 class FBConnectSettingsAction extends ConnectSettingsAction
47 {
48     /**
49      * Title of the page
50      *
51      * @return string Title of the page
52      */
53     function title()
54     {
55         return _m('Facebook Connect Settings');
56     }
57
58     /**
59      * Instructions for use
60      *
61      * @return instructions for use
62      */
63     function getInstructions()
64     {
65         return _m('Manage how your account connects to Facebook');
66     }
67
68     /**
69      * Content area of the page
70      *
71      * Shows a form for uploading an avatar.
72      *
73      * @return void
74      */
75     function showContent()
76     {
77         $user = common_current_user();
78         $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
79
80         $this->elementStart('form', array('method' => 'post',
81                                           'id' => 'form_settings_facebook',
82                                           'class' => 'form_settings',
83                                           'action' =>
84                                           common_local_url('FBConnectSettings')));
85
86         if (!$flink) {
87
88             $this->element('p', 'instructions',
89                 _m('There is no Facebook user connected to this account.'));
90
91             $this->element('fb:login-button', array('onlogin' => 'goto_login()',
92                 'length' => 'long'));
93
94         } else {
95
96             $this->element('p', 'form_note',
97                            _m('Connected Facebook user'));
98
99             $this->elementStart('p', array('class' => 'facebook-user-display'));
100             $this->elementStart('fb:profile-pic',
101                 array('uid' => $flink->foreign_id,
102                       'size' => 'small',
103                       'linked' => 'true',
104                       'facebook-logo' => 'true'));
105             $this->elementEnd('fb:profile-pic');
106
107             $this->elementStart('fb:name', array('uid' => $flink->foreign_id,
108                                                  'useyou' => 'false'));
109             $this->elementEnd('fb:name');
110             $this->elementEnd('p');
111
112             $this->hidden('token', common_session_token());
113
114             $this->elementStart('fieldset');
115
116             $this->element('legend', null, _m('Disconnect my account from Facebook'));
117
118             if (!$user->password) {
119
120                 $this->elementStart('p', array('class' => 'form_guide'));
121                 // @todo FIXME: Bad i18n. Patchwork message in three parts.
122                 // TRANS: Followed by a link containing text "set a password".
123                 $this->text(_m('Disconnecting your Faceboook ' .
124                                'would make it impossible to log in! Please '));
125                 $this->element('a',
126                     array('href' => common_local_url('passwordsettings')),
127                         // TRANS: Preceded by "Please " and followed by " first."
128                         _m('set a password'));
129                 // TRANS: Preceded by "Please set a password".
130                 $this->text(_m(' first.'));
131                 $this->elementEnd('p');
132             } else {
133
134                 $note = 'Keep your %s account but disconnect from Facebook. ' .
135                     'You\'ll use your %s password to log in.';
136
137                 $site = common_config('site', 'name');
138
139                 $this->element('p', 'instructions',
140                     sprintf($note, $site, $site));
141
142                 $this->submit('disconnect', _m('Disconnect'));
143             }
144
145             $this->elementEnd('fieldset');
146         }
147
148         $this->elementEnd('form');
149     }
150
151     /**
152      * Handle post
153      *
154      * Disconnects the current Facebook user from the current user's account
155      *
156      * @return void
157      */
158     function handlePost()
159     {
160         // CSRF protection
161         $token = $this->trimmed('token');
162         if (!$token || $token != common_session_token()) {
163             $this->showForm(_m('There was a problem with your session token. '.
164                                'Try again, please.'));
165             return;
166         }
167
168         if ($this->arg('disconnect')) {
169
170             $user = common_current_user();
171
172             $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
173             $result = $flink->delete();
174
175             if ($result === false) {
176                 common_log_db_error($user, 'DELETE', __FILE__);
177                 $this->serverError(_m('Couldn\'t delete link to Facebook.'));
178                 return;
179             }
180
181             try {
182
183                 // Clear FB Connect cookies out
184                 $facebook = getFacebook();
185                 $facebook->clear_cookie_state();
186
187             } catch (Exception $e) {
188                 common_log(LOG_WARNING, 'Facebook Connect Plugin - ' .
189                            'Couldn\'t clear Facebook cookies: ' .
190                            $e->getMessage());
191             }
192
193             $this->showForm(_m('You have disconnected from Facebook.'), true);
194
195         } else {
196             $this->showForm(_m('Not sure what you\'re trying to do.'));
197             return;
198         }
199
200     }
201 }