3 * StatusNet, the distributed open-source microblogging tool
5 * Form for editing an application
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 2009 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') && !defined('LACONICA')) {
34 require_once INSTALLDIR . '/lib/form.php';
37 * Form for editing an application
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class ApplicationEditForm extends Form
49 * group for user to join
51 var $application = null;
56 * @param Action $out output channel
57 * @param User_group $group group to join
59 function __construct($out=null, $application=null)
61 parent::__construct($out);
63 $this->application = $application;
69 * @return string ID of the form
73 if ($this->application) {
74 return 'form_application_edit-' . $this->application->id;
76 return 'form_application_add';
81 * HTTP method used to submit the form
83 * For image data we need to send multipart/form-data
84 * so we set that here too
86 * @return string the method to use for submitting
90 $this->enctype = 'multipart/form-data';
97 * @return string of the form class
101 return 'form_settings';
107 * @return string URL of the action
111 $cur = common_current_user();
113 if (!empty($this->application)) {
114 return common_local_url('editapplication',
115 array('id' => $this->application->id));
117 return common_local_url('newapplication');
126 function formLegend()
128 // TRANS: Form legend.
129 $this->out->element('legend', null, _('Edit application'));
133 * Data elements of the form
139 if ($this->application) {
140 $id = $this->application->id;
141 $icon = $this->application->icon;
142 $name = $this->application->name;
143 $description = $this->application->description;
144 $source_url = $this->application->source_url;
145 $organization = $this->application->organization;
146 $homepage = $this->application->homepage;
147 $callback_url = $this->application->callback_url;
148 $this->type = $this->application->type;
149 $this->access_type = $this->application->access_type;
160 $this->access_type = '';
163 $this->out->elementStart('ul', 'form_data');
165 $this->out->elementStart('li', array('id' => 'application_icon'));
168 $this->out->element('img', array('src' => $icon));
171 $this->out->element('label', array('for' => 'app_icon'),
172 // TRANS: Form input field label for application icon.
174 $this->out->element('input', array('name' => 'app_icon',
176 'id' => 'app_icon'));
177 // TRANS: Form guide.
178 $this->out->element('p', 'form_guide', _('Icon for this application'));
179 $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
181 'id' => 'MAX_FILE_SIZE',
182 'value' => ImageFile::maxFileSizeInt()));
183 $this->out->elementEnd('li');
185 $this->out->elementStart('li');
187 $this->out->hidden('application_id', $id);
189 // TRANS: Form input field label for application name.
190 $this->out->input('name', _('Name'),
191 ($this->out->arg('name')) ? $this->out->arg('name') : $name);
193 $this->out->elementEnd('li');
195 $this->out->elementStart('li');
197 $maxDesc = Oauth_application::maxDesc();
199 // TRANS: Form input field instructions.
200 $descInstr = sprintf(_('Describe your application in %d characters'),
203 // TRANS: Form input field instructions.
204 $descInstr = _('Describe your application');
206 // TRANS: Form input field label.
207 $this->out->textarea('description', _('Description'),
208 ($this->out->arg('description')) ? $this->out->arg('description') : $description,
211 $this->out->elementEnd('li');
213 $this->out->elementStart('li');
214 // TRANS: Form input field instructions.
215 $instruction = _('URL of the homepage of this application');
216 // TRANS: Form input field label.
217 $this->out->input('source_url', _('Source URL'),
218 ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
220 $this->out->elementEnd('li');
222 $this->out->elementStart('li');
223 // TRANS: Form input field instructions.
224 $instruction = _('Organization responsible for this application');
225 // TRANS: Form input field label.
226 $this->out->input('organization', _('Organization'),
227 ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
229 $this->out->elementEnd('li');
231 $this->out->elementStart('li');
232 // TRANS: Form input field instructions.
233 $instruction = _('URL for the homepage of the organization');
234 // TRANS: Form input field label.
235 $this->out->input('homepage', _('Homepage'),
236 ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
238 $this->out->elementEnd('li');
240 $this->out->elementStart('li');
241 // TRANS: Form input field instructions.
242 $instruction = _('URL to redirect to after authentication');
243 // TRANS: Form input field label.
244 $this->out->input('callback_url', ('Callback URL'),
245 ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
247 $this->out->elementEnd('li');
249 $this->out->elementStart('li', array('id' => 'application_types'));
251 $attrs = array('name' => 'app_type',
253 'id' => 'app_type-browser',
255 'value' => Oauth_application::$browser);
257 // Default to Browser
259 if (empty($this->application)
260 || empty($this->application->type)
261 || $this->application->type == Oauth_application::$browser) {
262 $attrs['checked'] = 'checked';
265 $this->out->element('input', $attrs);
267 $this->out->element('label', array('for' => 'app_type-browser',
269 // TRANS: Radio button label for application type
272 $attrs = array('name' => 'app_type',
274 'id' => 'app_type-dekstop',
276 'value' => Oauth_application::$desktop);
278 if (!empty($this->application) && $this->application->type == Oauth_application::$desktop) {
279 $attrs['checked'] = 'checked';
282 $this->out->element('input', $attrs);
284 $this->out->element('label', array('for' => 'app_type-desktop',
286 // TRANS: Radio button label for application type
288 // TRANS: Form guide.
289 $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
290 $this->out->elementEnd('li');
292 $this->out->elementStart('li', array('id' => 'default_access_types'));
294 $attrs = array('name' => 'default_access_type',
296 'id' => 'default_access_type-r',
300 // default to read-only access
302 if (empty($this->application)
303 || empty($this->application->access_type)
304 || $this->application->access_type & Oauth_application::$readAccess) {
305 $attrs['checked'] = 'checked';
308 $this->out->element('input', $attrs);
310 $this->out->element('label', array('for' => 'default_access_type-ro',
312 // TRANS: Radio button label for access type.
315 $attrs = array('name' => 'default_access_type',
317 'id' => 'default_access_type-rw',
321 if (!empty($this->application)
322 && $this->application->access_type & Oauth_application::$readAccess
323 && $this->application->access_type & Oauth_application::$writeAccess
325 $attrs['checked'] = 'checked';
328 $this->out->element('input', $attrs);
330 $this->out->element('label', array('for' => 'default_access_type-rw',
332 // TRANS: Radio button label for access type.
334 // TRANS: Form guide.
335 $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
337 $this->out->elementEnd('li');
339 $this->out->elementEnd('ul');
347 function formActions()
349 // TRANS: Button label in the "Edit application" form.
350 $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
351 // TRANS: Submit button title.
352 'cancel', _('Cancel'));
353 // TRANS: Button label in the "Edit application" form.
354 $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
355 // TRANS: Submit button title.