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. Maximum 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 // URLs should be set for cc license
166 if ($values['license']['type'] == 'cc') {
167 if (!Validate::uri($values['license']['url'], $options)) {
168 $this->clientError(_("Invalid license URL."));
170 if (!Validate::uri($values['license']['image'], $options)) {
171 $this->clientError(_("Invalid license image URL."));
175 // can be either blank or a valid URL for private & allrightsreserved
177 if (!empty($values['license']['url'])) {
178 if (!Validate::uri($values['license']['url'], $options)) {
179 $this->clientError(_("License URL must be blank or a valid URL."));
183 // can be either blank or a valid URL for private & allrightsreserved
185 if (!empty($values['license']['image'])) {
186 if (!Validate::uri($values['license']['image'], $options)) {
187 $this->clientError(_("License image must be blank or valid URL."));
193 class LicenseAdminPanelForm extends AdminForm
198 * @return int ID of the form
203 return 'licenseadminpanel';
209 * @return string class of the form
214 return 'form_settings';
220 * @return string URL of the action
225 return common_local_url('licenseadminpanel');
229 * Data elements of the form
236 $this->out->elementStart(
237 'fieldset', array('id' => 'settings_license-selection')
239 $this->out->element('legend', null, _('License selection'));
240 $this->out->elementStart('ul', 'form_data');
245 'private' => _('Private'),
246 'allrightsreserved' => _('All Rights Reserved'),
247 'cc' => _('Creative Commons')
250 $this->out->dropdown(
256 $this->value('type', 'license')
261 $this->out->elementEnd('ul');
262 $this->out->elementEnd('fieldset');
264 $this->out->elementStart(
266 array('id' => 'settings_license-details')
268 $this->out->element('legend', null, _('License details'));
269 $this->out->elementStart('ul', 'form_data');
275 _('Name of the owner of the site\'s content (if applicable).'),
284 _('The title of the license.'),
293 _('URL for more information about the license.'),
300 'image', _('License Image URL'),
301 _('URL for an image to display with the license.'),
306 $this->out->elementEnd('ul');
307 $this->out->elementEnd('fieldset');
316 function formActions()
319 'submit', _('Save'), 'submit', null, _('Save license settings')