]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/facebooksettings.php
Extract image management code to a helper function
[quix0rs-gnu-social.git] / actions / facebooksettings.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, 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('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
31         if ($this->arg('save')) {
32             $this->saveSettings();
33         } else {
34             $this->showForm();
35         }
36     }
37
38     function saveSettings() {
39
40         $noticesync = $this->arg('noticesync');
41         $replysync = $this->arg('replysync');
42         $prefix = $this->trimmed('prefix');
43
44         $facebook = get_facebook();
45         $fbuid = $facebook->require_login();
46
47         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
48
49         $original = clone($flink);
50         $flink->set_flags($noticesync, $replysync, false);
51         $result = $flink->update($original);
52
53         $facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
54             substr($prefix, 0, 128));
55
56         if ($result) {
57             $this->showForm('Sync preferences saved.', true);
58         } else {
59             $this->showForm('There was a problem saving your sync preferences!');
60         }
61     }
62
63     function showForm($msg = null, $success = false) {
64
65         $facebook = get_facebook();
66         $fbuid = $facebook->require_login();
67
68         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
69
70         $this->showHeader($msg, $success);
71         $this->showNav('Settings');
72
73         if ($facebook->api_client->users_hasAppPermission('status_update')) {
74
75             $this->elementStart('form', array('method' => 'post',
76                                                'id' => 'facebook_settings'));
77
78             $this->element('h2', null, _('Sync preferences'));
79
80             $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
81                                 ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
82
83             $this->checkbox('replysync', _('Send "@" replies to Facebook.'),
84                              ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
85
86             $prefix = $facebook->api_client->data_getUserPreference(1);
87
88             $this->input('prefix', _('Prefix'),
89                          ($prefix) ? $prefix : null,
90                          _('A string to prefix notices with.'));
91             $this->submit('save', _('Save'));
92
93             $this->elementEnd('form');
94
95         } else {
96
97             // Figure what the URL of our app is.
98             $app_props = $facebook->api_client->Admin_getAppProperties(
99                     array('canvas_name', 'application_name'));
100             $app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/settings.php';
101             $app_name = $app_props['application_name'];
102
103             $instructions = sprintf(_('If you would like the %s app to automatically update ' .
104                 'your Facebook status with your latest notice, you need ' .
105                 'to give it permission.'), $app_name);
106
107             $this->elementStart('p');
108             $this->element('span', array('id' => 'permissions_notice'), $instructions);
109             $this->elementEnd('p');
110
111             $this->elementStart('ul', array('id' => 'fb-permissions-list'));
112             $this->elementStart('li', array('id' => 'fb-permissions-item'));
113             $this->elementStart('fb:prompt-permission', array('perms' => 'status_update',
114                 'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')'));
115             $this->element('span', array('class' => 'facebook-button'),
116                 _('Allow Identi.ca to update my Facebook status'));
117             $this->elementEnd('fb:prompt-permission');
118             $this->elementEnd('li');
119             $this->elementEnd('ul');
120         }
121
122         $this->showFooter();
123     }
124
125 }