]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/FBConnect/FBConnectSettings.php
Added configurable options for attachments: supported mimetypes and quotas for uploads.
[quix0rs-gnu-social.git] / plugins / FBConnect / FBConnectSettings.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Zach Copley <zach@controlyourself.ca>
25  * @copyright 2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!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  Laconica
41  * @author   Zach Copley <zach@controlyourself.ca>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://laconi.ca/
44  */
45
46 class FBConnectSettingsAction extends ConnectSettingsAction
47 {
48     /**
49      * Title of the page
50      *
51      * @return string Title of the page
52      */
53
54     function title()
55     {
56         return _('Facebook Connect Settings');
57     }
58
59     /**
60      * Instructions for use
61      *
62      * @return instructions for use
63      */
64
65     function getInstructions()
66     {
67         return _('Manage how your account connects to Facebook');
68     }
69
70     /**
71      * Content area of the page
72      *
73      * Shows a form for uploading an avatar.
74      *
75      * @return void
76      */
77
78     function showContent()
79     {
80         $user = common_current_user();
81
82         $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
83
84         if (!$flink) {
85
86             $this->element('p', 'form_note',
87                 _('There is no Facebook user connected to this account.'));
88
89             $this->element('fb:login-button', array('onlogin' => 'goto_login()',
90                 'length' => 'long'));
91
92             return;
93         }
94
95         $this->element('p', 'form_note',
96                        _('Connected Facebook user:'));
97
98         $this->elementStart('p', array('class' => 'facebook-user-display'));
99         $this->elementStart('fb:profile-pic',
100             array('uid' => $flink->foreign_id,
101                   'size' => 'square',
102                   'linked' => 'true',
103                   'facebook-logo' => 'true'));
104         $this->elementEnd('fb:profile-pic');
105
106         $this->elementStart('fb:name', array('uid' => $flink->foreign_id));
107         $this->elementEnd('fb:name');
108         $this->elementEnd('p');
109
110         $this->elementStart('form', array('method' => 'post',
111                                           'id' => 'form_settings_facebook',
112                                           'class' => 'form_settings',
113                                           'action' =>
114                                           common_local_url('FBConnectSettings')));
115
116         $this->hidden('token', common_session_token());
117
118         $this->elementStart('fieldset');
119
120         $this->element('legend', null, _('Disconnect my account from Facebook'));
121
122         if (!$user->password) {
123
124             $this->elementStart('p', array('class' => 'form_guide'));
125             $this->text(_('Disconnecting your Faceboook ' .
126                           'would make it impossible to log in! Please '));
127             $this->element('a',
128                 array('href' => common_local_url('passwordsettings')),
129                     _('set a password'));
130
131             $this->text(_(' first.'));
132             $this->elementEnd('p');
133         } else {
134             $this->submit('disconnect', _('Disconnect'));
135          }
136
137         $this->elementEnd('fieldset');
138         $this->elementEnd('form');
139     }
140
141     /**
142      * Handle post
143      *
144      * Disconnects the current Facebook user from the current user's account
145      *
146      * @return void
147      */
148
149     function handlePost()
150     {
151         // CSRF protection
152         $token = $this->trimmed('token');
153         if (!$token || $token != common_session_token()) {
154             $this->showForm(_('There was a problem with your session token. '.
155                               'Try again, please.'));
156             return;
157         }
158
159         if ($this->arg('disconnect')) {
160
161             $user = common_current_user();
162
163             $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
164             $result = $flink->delete();
165
166             if ($result === false) {
167                 common_log_db_error($user, 'DELETE', __FILE__);
168                 $this->serverError(_('Couldn\'t delete link to Facebook.'));
169                 return;
170             }
171
172             try {
173
174                 // XXX: not sure what exactly to do here
175
176                 $facebook = getFacebook();
177                 $facebook->clear_cookie_state();
178
179             } catch (Exception $e) {
180                 common_log(LOG_WARNING,
181                     'Couldn\'t clear Facebook cookies: ' .
182                         $e->getMessage());
183             }
184
185             $this->showForm(_('Facebook user disconnected.'), true);
186
187         } else {
188             $this->showForm(_('Not sure what you\'re trying to do.'));
189             return;
190         }
191
192     }
193
194 }