3 * StatusNet, the distributed open-source microblogging tool
5 * License administration panel
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.
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.
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/>.
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/
30 if (!defined('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/
43 class LicenseadminpanelAction extends AdminPanelAction
46 * Returns the page title
48 * @return string page title
53 // TRANS: User admin panel title
54 return _m('TITLE', 'License');
58 * Instructions for using this form.
60 * @return string instructions
62 function getInstructions()
64 // TRANS: Form instructions for the site license admin panel.
65 return _('License for this StatusNet site');
69 * Show the site admin panel form
75 $form = new LicenseAdminPanelForm($this);
81 * Save settings from the form
85 function saveSettings()
87 static $settings = array(
88 'license' => array('type', 'owner', 'url', 'title', 'image')
93 foreach ($settings as $section => $parts) {
94 foreach ($parts as $setting) {
95 $values[$section][$setting] = $this->trimmed($setting);
99 // This throws an exception on validation errors
101 $this->validate($values);
103 // assert(all values are valid);
105 $config = new Config();
107 $config->query('BEGIN');
109 foreach ($settings as $section => $parts) {
110 foreach ($parts as $setting) {
111 Config::save($section, $setting, $values[$section][$setting]);
115 $config->query('COMMIT');
121 * Validate License admin form values
123 * @param array &$values from the form
127 function validate(&$values)
129 // Validate license type (shouldn't have to do it, but just in case)
131 $types = array('private', 'allrightsreserved', 'cc');
133 if (!in_array($values['license']['type'], $types)) {
134 // TRANS: Client error displayed selecting an invalid license in the license admin panel.
135 $this->clientError(_('Invalid license selection.'));
138 // Make sure the user has set an owner if the site has a private
141 if ($values['license']['type'] == 'allrightsreserved'
142 && empty($values['license']['owner'])
145 // TRANS: Client error displayed when not specifying an owner for the all rights reserved license in the license admin panel.
146 _('You must specify the owner of the content when using the All Rights Reserved license.')
150 // Make sure the license title is not too long
151 if (mb_strlen($values['license']['type']) > 255) {
153 // TRANS: Client error displayed selecting a too long license title in the license admin panel.
154 _('Invalid license title. Maximum length is 255 characters.')
158 // URLs should be set for cc license
160 if ($values['license']['type'] == 'cc') {
161 if (!common_valid_http_url($values['license']['url'])) {
162 // TRANS: Client error displayed specifying an invalid license URL in the license admin panel.
163 $this->clientError(_('Invalid license URL.'));
165 if (!common_valid_http_url($values['license']['image'])) {
166 // TRANS: Client error displayed specifying an invalid license image URL in the license admin panel.
167 $this->clientError(_('Invalid license image URL.'));
171 // can be either blank or a valid URL for private & allrightsreserved
173 if (!empty($values['license']['url'])) {
174 if (!common_valid_http_url($values['license']['url'])) {
175 // TRANS: Client error displayed specifying an invalid license URL in the license admin panel.
176 $this->clientError(_('License URL must be blank or a valid URL.'));
180 // can be either blank or a valid URL for private & allrightsreserved
182 if (!empty($values['license']['image'])) {
183 if (!common_valid_http_url($values['license']['image'])) {
184 // TRANS: Client error displayed specifying an invalid license image URL in the license admin panel.
185 $this->clientError(_('License image must be blank or valid URL.'));
191 class LicenseAdminPanelForm extends AdminForm
196 * @return int ID of the form
200 return 'licenseadminpanel';
206 * @return string class of the form
210 return 'form_settings';
216 * @return string URL of the action
221 return common_local_url('licenseadminpanel');
225 * Data elements of the form
232 $this->out->elementStart(
233 'fieldset', array('id' => 'settings_license-selection')
235 // TRANS: Form legend in the license admin panel.
236 $this->out->element('legend', null, _('License selection'));
237 $this->out->elementStart('ul', 'form_data');
242 // TRANS: License option in the license admin panel.
243 'private' => _('Private'),
244 // TRANS: License option in the license admin panel.
245 'allrightsreserved' => _('All Rights Reserved'),
246 // TRANS: License option in the license admin panel.
247 'cc' => _('Creative Commons')
250 $this->out->dropdown(
252 // TRANS: Dropdown field label in the license admin panel.
255 // TRANS: Dropdown field instructions in the license admin panel.
256 _('Select a license.'),
258 $this->value('type', 'license')
263 $this->out->elementEnd('ul');
264 $this->out->elementEnd('fieldset');
266 $this->out->elementStart(
268 array('id' => 'settings_license-details')
270 // TRANS: Form legend in the license admin panel.
271 $this->out->element('legend', null, _('License details'));
272 $this->out->elementStart('ul', 'form_data');
277 // TRANS: Field label in the license admin panel.
279 // TRANS: Field title in the license admin panel.
280 _('Name of the owner of the site\'s content (if applicable).'),
288 // TRANS: Field label in the license admin panel.
290 // TRANS: Field title in the license admin panel.
291 _('The title of the license.'),
299 // TRANS: Field label in the license admin panel.
301 // TRANS: Field title in the license admin panel.
302 _('URL for more information about the license.'),
309 // TRANS: Field label in the license admin panel.
310 'image', _('License Image URL'),
311 // TRANS: Field title in the license admin panel.
312 _('URL for an image to display with the license.'),
317 $this->out->elementEnd('ul');
318 $this->out->elementEnd('fieldset');
326 function formActions()
330 // TRANS: Button text in the license admin panel.
334 // TRANS: Button title in the license admin panel.
335 _('Save license settings.')