]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/facebooksettings.php
Remove Twitter bridge stuff. The relevant info has been moved to
[quix0rs-gnu-social.git] / actions / 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')) { 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         $this->showPage();
31     }
32
33     /**
34      * Show the page content
35      *
36      * Either shows the registration form or, if registration was successful,
37      * instructions for using the site.
38      *
39      * @return void
40      */
41
42     function showContent()
43     {
44         if ($this->arg('save')) {
45             $this->saveSettings();
46         } else {
47             $this->showForm();
48         }
49     }
50
51     function saveSettings() {
52
53         $noticesync = $this->arg('noticesync');
54         $replysync = $this->arg('replysync');
55         $prefix = $this->trimmed('prefix');
56
57         $original = clone($this->flink);
58         $this->flink->set_flags($noticesync, $replysync, false, false);
59         $result = $this->flink->update($original);
60
61         if ($prefix == '' || $prefix == '0') {
62                 // Facebook bug: saving empty strings to prefs now fails
63                 // http://bugs.developers.facebook.com/show_bug.cgi?id=7110
64                 $trimmed = $prefix . ' ';
65         } else {
66                 $trimmed = substr($prefix, 0, 128);
67             }
68         $this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
69             $trimmed);
70
71         if ($result === false) {
72             $this->showForm(_('There was a problem saving your sync preferences!'));
73         } else {
74             $this->showForm(_('Sync preferences saved.'), true);
75         }
76     }
77
78     function showForm($msg = null, $success = false) {
79
80         if ($msg) {
81             if ($success) {
82                 $this->element('fb:success', array('message' => $msg));
83             } else {
84                 $this->element('fb:error', array('message' => $msg));
85             }
86         }
87
88         if ($this->facebook->api_client->users_hasAppPermission('publish_stream')) {
89
90             $this->elementStart('form', array('method' => 'post',
91                                                'id' => 'facebook_settings'));
92
93             $this->elementStart('ul', 'form_data');
94                                            
95             $this->elementStart('li');
96             
97             $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
98                                 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true);
99
100             $this->elementEnd('li');
101             
102             $this->elementStart('li');
103             
104             $this->checkbox('replysync', _('Send "@" replies to Facebook.'),
105                              ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
106
107             $this->elementEnd('li');
108
109             $this->elementStart('li');
110
111             $prefix = trim($this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX));
112
113             $this->input('prefix', _('Prefix'),
114                          ($prefix) ? $prefix : null,
115                          _('A string to prefix notices with.'));
116
117             $this->elementEnd('li');
118             
119             $this->elementStart('li');
120             
121             $this->submit('save', _('Save'));
122
123             $this->elementEnd('li');
124
125             $this->elementEnd('ul');
126         
127             $this->elementEnd('form');
128
129         } else {
130
131             $instructions = sprintf(_('If you would like %s to automatically update ' .
132                 'your Facebook status with your latest notice, you need ' .
133                 'to give it permission.'), $this->app_name);
134
135             $this->elementStart('p');
136             $this->element('span', array('id' => 'permissions_notice'), $instructions);
137             $this->elementEnd('p');
138
139             $this->elementStart('ul', array('id' => 'fb-permissions-list'));
140             $this->elementStart('li', array('id' => 'fb-permissions-item'));
141             $this->elementStart('fb:prompt-permission', array('perms' => 'publish_stream',
142                 'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')'));
143             $this->element('span', array('class' => 'facebook-button'),
144                 sprintf(_('Allow %s to update my Facebook status'), common_config('site', 'name')));
145             $this->elementEnd('fb:prompt-permission');
146             $this->elementEnd('li');
147             $this->elementEnd('ul');
148         }
149
150     }
151     
152     function title() 
153     {
154         return _('Sync preferences');
155     }
156
157 }