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 // TRANS: %d is the number of available characters for the description.
201 $descInstr = sprintf(ngettext('Describe your application in %d character','Describe your application in %d characters',$maxDesc),
204 // TRANS: Form input field instructions.
205 $descInstr = _('Describe your application');
207 // TRANS: Form input field label.
208 $this->out->textarea('description', _('Description'),
209 ($this->out->arg('description')) ? $this->out->arg('description') : $description,
212 $this->out->elementEnd('li');
214 $this->out->elementStart('li');
215 // TRANS: Form input field instructions.
216 $instruction = _('URL of the homepage of this application');
217 // TRANS: Form input field label.
218 $this->out->input('source_url', _('Source URL'),
219 ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
221 $this->out->elementEnd('li');
223 $this->out->elementStart('li');
224 // TRANS: Form input field instructions.
225 $instruction = _('Organization responsible for this application');
226 // TRANS: Form input field label.
227 $this->out->input('organization', _('Organization'),
228 ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
230 $this->out->elementEnd('li');
232 $this->out->elementStart('li');
233 // TRANS: Form input field instructions.
234 $instruction = _('URL for the homepage of the organization');
235 // TRANS: Form input field label.
236 $this->out->input('homepage', _('Homepage'),
237 ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
239 $this->out->elementEnd('li');
241 $this->out->elementStart('li');
242 // TRANS: Form input field instructions.
243 $instruction = _('URL to redirect to after authentication');
244 // TRANS: Form input field label.
245 $this->out->input('callback_url', ('Callback URL'),
246 ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
248 $this->out->elementEnd('li');
250 $this->out->elementStart('li', array('id' => 'application_types'));
252 $attrs = array('name' => 'app_type',
254 'id' => 'app_type-browser',
256 'value' => Oauth_application::$browser);
258 // Default to Browser
260 if (empty($this->application)
261 || empty($this->application->type)
262 || $this->application->type == Oauth_application::$browser) {
263 $attrs['checked'] = 'checked';
266 $this->out->element('input', $attrs);
268 $this->out->element('label', array('for' => 'app_type-browser',
270 // TRANS: Radio button label for application type
273 $attrs = array('name' => 'app_type',
275 'id' => 'app_type-dekstop',
277 'value' => Oauth_application::$desktop);
279 if (!empty($this->application) && $this->application->type == Oauth_application::$desktop) {
280 $attrs['checked'] = 'checked';
283 $this->out->element('input', $attrs);
285 $this->out->element('label', array('for' => 'app_type-desktop',
287 // TRANS: Radio button label for application type
289 // TRANS: Form guide.
290 $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
291 $this->out->elementEnd('li');
293 $this->out->elementStart('li', array('id' => 'default_access_types'));
295 $attrs = array('name' => 'default_access_type',
297 'id' => 'default_access_type-r',
301 // default to read-only access
303 if (empty($this->application)
304 || empty($this->application->access_type)
305 || $this->application->access_type & Oauth_application::$readAccess) {
306 $attrs['checked'] = 'checked';
309 $this->out->element('input', $attrs);
311 $this->out->element('label', array('for' => 'default_access_type-ro',
313 // TRANS: Radio button label for access type.
316 $attrs = array('name' => 'default_access_type',
318 'id' => 'default_access_type-rw',
322 if (!empty($this->application)
323 && $this->application->access_type & Oauth_application::$readAccess
324 && $this->application->access_type & Oauth_application::$writeAccess
326 $attrs['checked'] = 'checked';
329 $this->out->element('input', $attrs);
331 $this->out->element('label', array('for' => 'default_access_type-rw',
333 // TRANS: Radio button label for access type.
335 // TRANS: Form guide.
336 $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
338 $this->out->elementEnd('li');
340 $this->out->elementEnd('ul');
348 function formActions()
350 // TRANS: Button label in the "Edit application" form.
351 $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
352 // TRANS: Submit button title.
353 'cancel', _('Cancel'));
354 // TRANS: Button label in the "Edit application" form.
355 $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
356 // TRANS: Submit button title.