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/
47 class ApplicationEditForm extends Form
50 * group for user to join
53 var $application = null;
58 * @param Action $out output channel
59 * @param User_group $group group to join
62 function __construct($out=null, $application=null)
64 parent::__construct($out);
66 $this->application = $application;
72 * @return string ID of the form
77 if ($this->application) {
78 return 'form_application_edit-' . $this->application->id;
80 return 'form_application_add';
85 * HTTP method used to submit the form
87 * For image data we need to send multipart/form-data
88 * so we set that here too
90 * @return string the method to use for submitting
95 $this->enctype = 'multipart/form-data';
102 * @return string of the form class
107 return 'form_settings';
113 * @return string URL of the action
118 $cur = common_current_user();
120 if (!empty($this->application)) {
121 return common_local_url('editapplication',
122 array('id' => $this->application->id));
124 return common_local_url('newapplication');
134 function formLegend()
136 $this->out->element('legend', null, _('Edit application'));
140 * Data elements of the form
147 if ($this->application) {
148 $id = $this->application->id;
149 $icon = $this->application->icon;
150 $name = $this->application->name;
151 $description = $this->application->description;
152 $source_url = $this->application->source_url;
153 $organization = $this->application->organization;
154 $homepage = $this->application->homepage;
155 $callback_url = $this->application->callback_url;
156 $this->type = $this->application->type;
157 $this->access_type = $this->application->access_type;
168 $this->access_type = '';
171 $this->out->elementStart('ul', 'form_data');
173 $this->out->elementStart('li', array('id' => 'application_icon'));
176 $this->out->element('img', array('src' => $icon));
179 $this->out->element('label', array('for' => 'app_icon'),
181 $this->out->element('input', array('name' => 'app_icon',
183 'id' => 'app_icon'));
184 $this->out->element('p', 'form_guide', _('Icon for this application'));
185 $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
187 'id' => 'MAX_FILE_SIZE',
188 'value' => ImageFile::maxFileSizeInt()));
189 $this->out->elementEnd('li');
191 $this->out->elementStart('li');
193 $this->out->hidden('application_id', $id);
195 $this->out->input('name', _('Name'),
196 ($this->out->arg('name')) ? $this->out->arg('name') : $name);
198 $this->out->elementEnd('li');
200 $this->out->elementStart('li');
202 $maxDesc = Oauth_application::maxDesc();
204 $descInstr = sprintf(_('Describe your application in %d characters'),
207 $descInstr = _('Describe your application');
209 $this->out->textarea('description', _('Description'),
210 ($this->out->arg('description')) ? $this->out->arg('description') : $description,
213 $this->out->elementEnd('li');
215 $this->out->elementStart('li');
216 $this->out->input('source_url', _('Source URL'),
217 ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
218 _('URL of the homepage of this application'));
219 $this->out->elementEnd('li');
221 $this->out->elementStart('li');
222 $this->out->input('organization', _('Organization'),
223 ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
224 _('Organization responsible for this application'));
225 $this->out->elementEnd('li');
227 $this->out->elementStart('li');
228 $this->out->input('homepage', _('Homepage'),
229 ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
230 _('URL for the homepage of the organization'));
231 $this->out->elementEnd('li');
233 $this->out->elementStart('li');
234 $this->out->input('callback_url', ('Callback URL'),
235 ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
236 _('URL to redirect to after authentication'));
237 $this->out->elementEnd('li');
239 $this->out->elementStart('li', array('id' => 'application_types'));
241 $attrs = array('name' => 'app_type',
243 'id' => 'app_type-browser',
245 'value' => Oauth_application::$browser);
247 // Default to Browser
249 if ($this->application->type == Oauth_application::$browser
250 || empty($this->application->type)) {
251 $attrs['checked'] = 'checked';
254 $this->out->element('input', $attrs);
256 $this->out->element('label', array('for' => 'app_type-browser',
260 $attrs = array('name' => 'app_type',
262 'id' => 'app_type-dekstop',
264 'value' => Oauth_application::$desktop);
266 if ($this->application->type == Oauth_application::$desktop) {
267 $attrs['checked'] = 'checked';
270 $this->out->element('input', $attrs);
272 $this->out->element('label', array('for' => 'app_type-desktop',
275 $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
276 $this->out->elementEnd('li');
278 $this->out->elementStart('li', array('id' => 'default_access_types'));
280 $attrs = array('name' => 'default_access_type',
282 'id' => 'default_access_type-r',
286 // default to read-only access
288 if ($this->application->access_type & Oauth_application::$readAccess
289 || empty($this->application->access_type)) {
290 $attrs['checked'] = 'checked';
293 $this->out->element('input', $attrs);
295 $this->out->element('label', array('for' => 'default_access_type-ro',
299 $attrs = array('name' => 'default_access_type',
301 'id' => 'default_access_type-rw',
305 if ($this->application->access_type & Oauth_application::$readAccess
306 && $this->application->access_type & Oauth_application::$writeAccess
308 $attrs['checked'] = 'checked';
311 $this->out->element('input', $attrs);
313 $this->out->element('label', array('for' => 'default_access_type-rw',
316 $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
318 $this->out->elementEnd('li');
320 $this->out->elementEnd('ul');
329 function formActions()
331 $this->out->submit('cancel', _('Cancel'), 'submit form_action-primary',
332 'cancel', _('Cancel'));
333 $this->out->submit('save', _('Save'), 'submit form_action-secondary',