]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/FBConnectSettings.php
Merge branch '1.0.x' into schema-x
[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 class FBConnectSettingsAction extends ConnectSettingsAction
46 {
47     /**
48      * Title of the page
49      *
50      * @return string Title of the page
51      */
52     function title()
53     {
54         // TRANS: Page title.
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         // TRANS: Instructions.
66         return _m('Manage how your account connects to Facebook');
67     }
68
69     /**
70      * Content area of the page
71      *
72      * Shows a form for uploading an avatar.
73      *
74      * @return void
75      */
76     function showContent()
77     {
78         $user = common_current_user();
79         $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
80
81         $this->elementStart('form', array('method' => 'post',
82                                           'id' => 'form_settings_facebook',
83                                           'class' => 'form_settings',
84                                           'action' =>
85                                           common_local_url('FBConnectSettings')));
86
87         if (!$flink) {
88
89             $this->element('p', 'instructions',
90                 _m('There is no Facebook user connected to this account.'));
91
92             $this->element('fb:login-button', array('onlogin' => 'goto_login()',
93                 'length' => 'long'));
94
95         } else {
96
97             $this->element('p', 'form_note',
98                            _m('Connected Facebook user'));
99
100             $this->elementStart('p', array('class' => 'facebook-user-display'));
101             $this->elementStart('fb:profile-pic',
102                 array('uid' => $flink->foreign_id,
103                       'size' => 'small',
104                       'linked' => 'true',
105                       'facebook-logo' => 'true'));
106             $this->elementEnd('fb:profile-pic');
107
108             $this->elementStart('fb:name', array('uid' => $flink->foreign_id,
109                                                  'useyou' => 'false'));
110             $this->elementEnd('fb:name');
111             $this->elementEnd('p');
112
113             $this->hidden('token', common_session_token());
114
115             $this->elementStart('fieldset');
116
117             // TRANS: Legend.
118             $this->element('legend', null, _m('Disconnect my account from Facebook'));
119
120             if (!$user->password) {
121
122                 $this->elementStart('p', array('class' => 'form_guide'));
123                 // @todo FIXME: Bad i18n. Patchwork message in three parts.
124                 // TRANS: Followed by a link containing text "set a password".
125                 $this->text(_m('Disconnecting your Faceboook ' .
126                                'would make it impossible to log in! Please '));
127                 $this->element('a',
128                     array('href' => common_local_url('passwordsettings')),
129                         // TRANS: Preceded by "Please " and followed by " first."
130                         _m('set a password'));
131                 // TRANS: Preceded by "Please set a password".
132                 $this->text(_m(' first.'));
133                 $this->elementEnd('p');
134             } else {
135
136                 $note = 'Keep your %s account but disconnect from Facebook. ' .
137                     'You\'ll use your %s password to log in.';
138
139                 $site = common_config('site', 'name');
140
141                 $this->element('p', 'instructions',
142                     sprintf($note, $site, $site));
143
144                 // TRANS: Submit button.
145                 $this->submit('disconnect', _m('BUTTON','Disconnect'));
146             }
147
148             $this->elementEnd('fieldset');
149         }
150
151         $this->elementEnd('form');
152     }
153
154     /**
155      * Handle post
156      *
157      * Disconnects the current Facebook user from the current user's account
158      *
159      * @return void
160      */
161     function handlePost()
162     {
163         // CSRF protection
164         $token = $this->trimmed('token');
165         if (!$token || $token != common_session_token()) {
166             $this->showForm(_m('There was a problem with your session token. '.
167                                'Try again, please.'));
168             return;
169         }
170
171         if ($this->arg('disconnect')) {
172
173             $user = common_current_user();
174
175             $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
176             $result = $flink->delete();
177
178             if ($result === false) {
179                 common_log_db_error($user, 'DELETE', __FILE__);
180                 $this->serverError(_m('Couldn\'t delete link to Facebook.'));
181                 return;
182             }
183
184             try {
185
186                 // Clear FB Connect cookies out
187                 $facebook = getFacebook();
188                 $facebook->clear_cookie_state();
189
190             } catch (Exception $e) {
191                 common_log(LOG_WARNING, 'Facebook Connect Plugin - ' .
192                            'Couldn\'t clear Facebook cookies: ' .
193                            $e->getMessage());
194             }
195
196             $this->showForm(_m('You have disconnected from Facebook.'), true);
197
198         } else {
199             $this->showForm(_m('Not sure what you\'re trying to do.'));
200             return;
201         }
202     }
203 }