]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/FacebookBridge/actions/facebookadminpanel.php
Introduced common_location_shared() to check if location sharing is always,
[quix0rs-gnu-social.git] / plugins / FacebookBridge / actions / facebookadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Facebook integration administration panel
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 2010 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')) {
31     exit(1);
32 }
33
34 /**
35  * Administer global Facebook integration settings
36  *
37  * @category Admin
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class FacebookadminpanelAction extends AdminPanelAction
44 {
45     /**
46      * Returns the page title
47      *
48      * @return string page title
49      */
50     function title()
51     {
52         // TRANS: Title for Facebook administration panel.
53         return _m('TITLE','Facebook integration settings');
54     }
55
56     /**
57      * Instructions for using this form.
58      *
59      * @return string instructions
60      */
61     function getInstructions()
62     {
63         // TRANS: Instruction for Facebook administration panel.
64         return _m('Facebook integration settings');
65     }
66
67     /**
68      * Show the Facebook admin panel form
69      *
70      * @return void
71      */
72     function showForm()
73     {
74         $form = new FacebookAdminPanelForm($this);
75         $form->show();
76         return;
77     }
78
79     /**
80      * Save settings from the form
81      *
82      * @return void
83      */
84     function saveSettings()
85     {
86         static $settings = array(
87             'facebook' => array('appid', 'secret'),
88         );
89
90         $values = array();
91
92         foreach ($settings as $section => $parts) {
93             foreach ($parts as $setting) {
94                 $values[$section][$setting]
95                     = $this->trimmed($setting);
96             }
97         }
98
99         // This throws an exception on validation errors
100         $this->validate($values);
101
102         // assert(all values are valid);
103
104         $config = new Config();
105
106         $config->query('BEGIN');
107
108         foreach ($settings as $section => $parts) {
109             foreach ($parts as $setting) {
110                 Config::save($section, $setting, $values[$section][$setting]);
111             }
112         }
113
114         $config->query('COMMIT');
115
116         return;
117     }
118
119     function validate(&$values)
120     {
121         // appId, key and secret (can't be too long)
122
123         if (mb_strlen($values['facebook']['appid']) > 255) {
124             $this->clientError(
125                 // TRANS: Client error displayed when providing too long a Facebook application ID.
126                 _m("Invalid Facebook ID. Maximum length is 255 characters.")
127             );
128         }
129
130         if (mb_strlen($values['facebook']['secret']) > 255) {
131             $this->clientError(
132                 // TRANS: Client error displayed when providing too long a Facebook secret key.
133                 _m("Invalid Facebook secret. Maximum length is 255 characters.")
134             );
135         }
136     }
137 }
138
139 class FacebookAdminPanelForm extends AdminForm
140 {
141     /**
142      * ID of the form
143      *
144      * @return int ID of the form
145      */
146     function id()
147     {
148         return 'facebookadminpanel';
149     }
150
151     /**
152      * class of the form
153      *
154      * @return string class of the form
155      */
156     function formClass()
157     {
158         return 'form_settings';
159     }
160
161     /**
162      * Action of the form
163      *
164      * @return string URL of the action
165      */
166     function action()
167     {
168         return common_local_url('facebookadminpanel');
169     }
170
171     /**
172      * Data elements of the form
173      *
174      * @return void
175      */
176     function formData()
177     {
178         $this->out->elementStart(
179             'fieldset',
180             array('id' => 'settings_facebook-application')
181         );
182         // TRANS: Fieldset legend.
183         $this->out->element('legend', null, _m('Facebook application settings'));
184         $this->out->elementStart('ul', 'form_data');
185
186         $this->li();
187         $this->input(
188             'appid',
189             // TRANS: Field label for Facebook application ID.
190             _m('Application ID'),
191             // TRANS: Field title for Facebook application ID.
192             _m('ID of your Facebook application.'),
193             'facebook'
194         );
195         $this->unli();
196
197         $this->li();
198         $this->input(
199             'secret',
200             // TRANS: Field label for Facebook secret key.
201             _m('Secret'),
202             // TRANS: Field title for Facebook secret key.
203             _m('Application secret.'),
204             'facebook'
205         );
206         $this->unli();
207
208         $this->out->elementEnd('ul');
209         $this->out->elementEnd('fieldset');
210     }
211
212     /**
213      * Action elements
214      *
215      * @return void
216      */
217     function formActions()
218     {
219         // TRANS: Button text to save Facebook integration settings.
220         $this->out->submit('submit', _m('BUTTON','Save'),
221                            // TRANS: Button title to save Facebook integration settings.
222                            'submit', null, _m('Save Facebook settings.'));
223     }
224 }