]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/facebookadminpanel.php
Merge branch '1.0.x' into schema-x
[quix0rs-gnu-social.git] / plugins / Facebook / 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         return _m('Facebook');
53     }
54
55     /**
56      * Instructions for using this form.
57      *
58      * @return string instructions
59      */
60     function getInstructions()
61     {
62         return _m('Facebook integration settings');
63     }
64
65     /**
66      * Show the Facebook admin panel form
67      *
68      * @return void
69      */
70     function showForm()
71     {
72         $form = new FacebookAdminPanelForm($this);
73         $form->show();
74         return;
75     }
76
77     /**
78      * Save settings from the form
79      *
80      * @return void
81      */
82     function saveSettings()
83     {
84         static $settings = array(
85             'facebook'     => array('apikey', 'secret'),
86         );
87
88         $values = array();
89
90         foreach ($settings as $section => $parts) {
91             foreach ($parts as $setting) {
92                 $values[$section][$setting]
93                     = $this->trimmed($setting);
94             }
95         }
96
97         // This throws an exception on validation errors
98         $this->validate($values);
99
100         // assert(all values are valid);
101
102         $config = new Config();
103
104         $config->query('BEGIN');
105
106         foreach ($settings as $section => $parts) {
107             foreach ($parts as $setting) {
108                 Config::save($section, $setting, $values[$section][$setting]);
109             }
110         }
111
112         $config->query('COMMIT');
113
114         return;
115     }
116
117     function validate(&$values)
118     {
119         // Validate consumer key and secret (can't be too long)
120
121         if (mb_strlen($values['facebook']['apikey']) > 255) {
122             $this->clientError(
123                 _m("Invalid Facebook API key. Max length is 255 characters.")
124             );
125         }
126
127         if (mb_strlen($values['facebook']['secret']) > 255) {
128             $this->clientError(
129                 _m("Invalid Facebook API secret. Max length is 255 characters.")
130             );
131         }
132     }
133 }
134
135 class FacebookAdminPanelForm extends AdminForm
136 {
137     /**
138      * ID of the form
139      *
140      * @return int ID of the form
141      */
142     function id()
143     {
144         return 'facebookadminpanel';
145     }
146
147     /**
148      * class of the form
149      *
150      * @return string class of the form
151      */
152     function formClass()
153     {
154         return 'form_settings';
155     }
156
157     /**
158      * Action of the form
159      *
160      * @return string URL of the action
161      */
162     function action()
163     {
164         return common_local_url('facebookadminpanel');
165     }
166
167     /**
168      * Data elements of the form
169      *
170      * @return void
171      */
172     function formData()
173     {
174         $this->out->elementStart(
175             'fieldset',
176             array('id' => 'settings_facebook-application')
177         );
178         $this->out->element('legend', null, _m('Facebook application settings'));
179         $this->out->elementStart('ul', 'form_data');
180
181         $this->li();
182         $this->input(
183             'apikey',
184             _m('API key'),
185             _m('API key provided by Facebook'),
186             'facebook'
187         );
188         $this->unli();
189
190         $this->li();
191         $this->input(
192             'secret',
193              _m('Secret'),
194             _m('API secret provided by Facebook'),
195             'facebook'
196         );
197         $this->unli();
198
199         $this->out->elementEnd('ul');
200         $this->out->elementEnd('fieldset');
201     }
202
203     /**
204      * Action elements
205      *
206      * @return void
207      */
208     function formActions()
209     {
210         $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save Facebook settings'));
211     }
212 }