]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/facebooksettings.php
Merge branch '1.0.x' into schema-x
[quix0rs-gnu-social.git] / plugins / Facebook / 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')) {
21     exit(1);
22 }
23
24 require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
25
26 class FacebooksettingsAction extends FacebookAction
27 {
28     function handle($args)
29     {
30         parent::handle($args);
31         $this->showPage();
32     }
33
34     /**
35      * Show the page content
36      *
37      * Either shows the registration form or, if registration was successful,
38      * instructions for using the site.
39      *
40      * @return void
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->boolean('noticesync');
54         $replysync  = $this->boolean('replysync');
55
56         $original = clone($this->flink);
57         $this->flink->set_flags($noticesync, false, $replysync, false);
58         $result = $this->flink->update($original);
59
60         if ($result === false) {
61             $this->showForm(_m('There was a problem saving your sync preferences!'));
62         } else {
63             // TRANS: Confirmation that synchronisation settings have been saved into the system.
64             $this->showForm(_m('Sync preferences saved.'), true);
65         }
66     }
67
68     function showForm($msg = null, $success = false) {
69
70         if ($msg) {
71             if ($success) {
72                 $this->element('fb:success', array('message' => $msg));
73             } else {
74                 $this->element('fb:error', array('message' => $msg));
75             }
76         }
77
78         if ($this->facebook->api_client->users_hasAppPermission('publish_stream')) {
79
80             $this->elementStart('form', array('method' => 'post',
81                                                'id' => 'facebook_settings'));
82
83             $this->elementStart('ul', 'form_data');
84
85             $this->elementStart('li');
86
87             $this->checkbox('noticesync', _m('Automatically update my Facebook status with my notices.'),
88                                 ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true);
89
90             $this->elementEnd('li');
91
92             $this->elementStart('li');
93
94             $this->checkbox('replysync', _m('Send "@" replies to Facebook.'),
95                              ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
96
97             $this->elementEnd('li');
98
99             $this->elementStart('li');
100
101             // TRANS: Submit button to save synchronisation settings.
102             $this->submit('save', _m('BUTTON','Save'));
103
104             $this->elementEnd('li');
105
106             $this->elementEnd('ul');
107
108             $this->elementEnd('form');
109         } else {
110             // TRANS: %s is the application name.
111             $instructions = sprintf(_m('If you would like %s to automatically update ' .
112                 'your Facebook status with your latest notice, you need ' .
113                 'to give it permission.'), $this->app_name);
114
115             $this->elementStart('p');
116             $this->element('span', array('id' => 'permissions_notice'), $instructions);
117             $this->elementEnd('p');
118
119             $this->elementStart('ul', array('id' => 'fb-permissions-list'));
120             $this->elementStart('li', array('id' => 'fb-permissions-item'));
121             $this->elementStart('fb:prompt-permission', array('perms' => 'publish_stream',
122                 'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')'));
123             $this->element('span', array('class' => 'facebook-button'),
124                 sprintf(_m('Allow %s to update my Facebook status'), common_config('site', 'name')));
125             $this->elementEnd('fb:prompt-permission');
126             $this->elementEnd('li');
127             $this->elementEnd('ul');
128         }
129     }
130
131     function title()
132     {
133         // TRANS: Page title for synchronisation settings.
134         return _m('Sync preferences');
135     }
136 }