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/
44 class LicenseadminpanelAction extends AdminPanelAction
48 * Returns the page title
50 * @return string page title
55 // TRANS: User admin panel title
56 return _m('TITLE', 'License');
60 * Instructions for using this form.
62 * @return string instructions
65 function getInstructions()
67 return _('License for this StatusNet site');
71 * Show the site admin panel form
78 $form = new LicenseAdminPanelForm($this);
84 * Save settings from the form
89 function saveSettings()
91 static $settings = array(
92 'license' => array('type', 'owner', 'url', 'title', 'image')
97 foreach ($settings as $section => $parts) {
98 foreach ($parts as $setting) {
99 $values[$section][$setting] = $this->trimmed($setting);
103 // This throws an exception on validation errors
105 $this->validate($values);
107 // assert(all values are valid);
109 $config = new Config();
111 $config->query('BEGIN');
113 foreach ($settings as $section => $parts) {
114 foreach ($parts as $setting) {
115 Config::save($section, $setting, $values[$section][$setting]);
119 $config->query('COMMIT');
125 * Validate License admin form values
127 * @param array &$values from the form
132 function validate(&$values)
134 // Validate license type (shouldn't have to do it, but just in case)
136 $types = array('private', 'allrightsreserved', 'cc');
138 if (!in_array($values['license']['type'], $types)) {
139 $this->clientError(_("Invalid license selection."));
142 // Make sure the user has set an owner if the site has a private
145 if ($values['license']['type'] == 'allrightsreserved'
146 && empty($values['license']['owner'])
149 _("You must specify the owner of the content when using the All Rights Reserved license.")
153 // Make sure the license title is not too long
154 if (mb_strlen($values['license']['type']) > 255) {
156 _("Invalid license title. Max length is 255 characters.")
160 // make sure the license URL and license image URL are valid URLs
162 $options = array('allowed_schemes' => array('http', 'https'));
164 if (!Validate::uri($values['license']['url'], $options)) {
165 $this->clientError(_("Invalid license URL."));
168 if (!Validate::uri($values['license']['image'], $options)) {
169 $this->clientError(_("Invalid license image URL."));
174 class LicenseAdminPanelForm extends AdminForm
179 * @return int ID of the form
184 return 'licenseadminpanel';
190 * @return string class of the form
195 return 'form_settings';
201 * @return string URL of the action
206 return common_local_url('licenseadminpanel');
210 * Data elements of the form
217 $this->out->elementStart(
218 'fieldset', array('id' => 'settings_license-selection')
220 $this->out->element('legend', null, _('License selection'));
221 $this->out->elementStart('ul', 'form_data');
226 'private' => _('Private'),
227 'allrightsreserved' => _('All Rights Reserved'),
228 'cc' => _('Creative Commons')
231 $this->out->dropdown(
237 $this->value('type', 'license')
242 $this->out->elementEnd('ul');
243 $this->out->elementEnd('fieldset');
245 $this->out->elementStart(
247 array('id' => 'settings_license-details')
249 $this->out->element('legend', null, _('License details'));
250 $this->out->elementStart('ul', 'form_data');
256 _('Name of the owner of the site\'s content (if applicable).'),
265 _('The title of the license.'),
274 _('URL for more information about the license.'),
281 'image', _('License Image URL'),
282 _('URL for an image to display with the license.'),
287 $this->out->elementEnd('ul');
288 $this->out->elementEnd('fieldset');
297 function formActions()
300 'submit', _('Save'), 'submit', null, _('Save license settings')