]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/licenseadminpanel.php
Merge branch 'master' into 0.9.x
[quix0rs-gnu-social.git] / actions / licenseadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * License 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  * License 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
44 class LicenseadminpanelAction extends AdminPanelAction
45 {
46
47     /**
48      * Returns the page title
49      *
50      * @return string page title
51      */
52
53     function title()
54     {
55         // TRANS: User admin panel title
56         return _m('TITLE', 'License');
57     }
58
59     /**
60      * Instructions for using this form.
61      *
62      * @return string instructions
63      */
64
65     function getInstructions()
66     {
67         return _('License for this StatusNet site');
68     }
69
70     /**
71      * Show the site admin panel form
72      *
73      * @return void
74      */
75
76     function showForm()
77     {
78         $form = new LicenseAdminPanelForm($this);
79         $form->show();
80         return;
81     }
82
83     /**
84      * Save settings from the form
85      *
86      * @return void
87      */
88
89     function saveSettings()
90     {
91         static $settings = array(
92             'license' => array('type', 'owner', 'url', 'title', 'image')
93         );
94
95         $values = array();
96
97         foreach ($settings as $section => $parts) {
98             foreach ($parts as $setting) {
99                 $values[$section][$setting] = $this->trimmed($setting);
100             }
101         }
102
103         // This throws an exception on validation errors
104
105         $this->validate($values);
106
107         // assert(all values are valid);
108
109         $config = new Config();
110
111         $config->query('BEGIN');
112
113         foreach ($settings as $section => $parts) {
114             foreach ($parts as $setting) {
115                 Config::save($section, $setting, $values[$section][$setting]);
116             }
117         }
118
119         $config->query('COMMIT');
120
121         return;
122     }
123
124     /**
125      * Validate License admin form values
126      *
127      * @param array &$values from the form
128      *
129      * @return nothing
130      */
131
132     function validate(&$values)
133     {
134         // Validate license type (shouldn't have to do it, but just in case)
135
136         $types = array('private', 'allrightsreserved', 'cc');
137
138         if (!in_array($values['license']['type'], $types)) {
139             $this->clientError(_("Invalid license selection."));
140         }
141
142         // Make sure the user has set an owner if the site has a private
143         // license
144
145         if ($values['license']['type'] == 'allrightsreserved'
146             && empty($values['license']['owner'])
147         ) {
148             $this->clientError(
149                 _("You must specify the owner of the content when using the All Rights Reserved license.")
150             );
151         }
152
153         // Make sure the license title is not too long
154         if (mb_strlen($values['license']['type']) > 255) {
155             $this->clientError(
156                 _("Invalid license title. Max length is 255 characters.")
157             );
158         }
159
160         // make sure the license URL and license image URL are valid URLs
161
162         $options = array('allowed_schemes' => array('http', 'https'));
163
164         if (!Validate::uri($values['license']['url'], $options)) {
165             $this->clientError(_("Invalid license URL."));
166         }
167
168         if (!Validate::uri($values['license']['image'], $options)) {
169             $this->clientError(_("Invalid license image URL."));
170         }
171     }
172 }
173
174 class LicenseAdminPanelForm extends AdminForm
175 {
176     /**
177      * ID of the form
178      *
179      * @return int ID of the form
180      */
181
182     function id()
183     {
184         return 'licenseadminpanel';
185     }
186
187     /**
188      * class of the form
189      *
190      * @return string class of the form
191      */
192
193     function formClass()
194     {
195         return 'form_settings';
196     }
197
198     /**
199      * Action of the form
200      *
201      * @return string URL of the action
202      */
203
204     function action()
205     {
206         return common_local_url('licenseadminpanel');
207     }
208
209     /**
210      * Data elements of the form
211      *
212      * @return void
213      */
214
215     function formData()
216     {
217         $this->out->elementStart(
218             'fieldset', array('id' => 'settings_license-selection')
219         );
220         $this->out->element('legend', null, _('License selection'));
221         $this->out->elementStart('ul', 'form_data');
222
223         $this->li();
224
225         $types = array(
226             'private' => _('Private'),
227             'allrightsreserved' => _('All Rights Reserved'),
228             'cc' => _('Creative Commons')
229         );
230
231         $this->out->dropdown(
232             'type',
233             _('Type'),
234             $types,
235             _('Select license'),
236             false,
237             $this->value('type', 'license')
238         );
239
240         $this->unli();
241
242         $this->out->elementEnd('ul');
243         $this->out->elementEnd('fieldset');
244
245         $this->out->elementStart(
246             'fieldset',
247             array('id' => 'settings_license-details')
248         );
249         $this->out->element('legend', null, _('License details'));
250         $this->out->elementStart('ul', 'form_data');
251
252         $this->li();
253         $this->input(
254             'owner',
255             _('Owner'),
256             _('Name of the owner of the site\'s content (if applicable).'),
257             'license'
258         );
259         $this->unli();
260
261         $this->li();
262         $this->input(
263             'title',
264             _('License Title'),
265             _('The title of the license.'),
266             'license'
267         );
268         $this->unli();
269
270         $this->li();
271         $this->input(
272             'url',
273             _('License URL'),
274             _('URL for more information about the license.'),
275             'license'
276         );
277         $this->unli();
278
279         $this->li();
280         $this->input(
281             'image', _('License Image URL'),
282             _('URL for an image to display with the license.'),
283             'license'
284         );
285         $this->unli();
286
287         $this->out->elementEnd('ul');
288         $this->out->elementEnd('fieldset');
289     }
290
291     /**
292      * Action elements
293      *
294      * @return void
295      */
296
297     function formActions()
298     {
299         $this->out->submit(
300             'submit', _('Save'), 'submit', null, _('Save license settings')
301         );
302     }
303 }