]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationeditform.php
Updated markup for application edit form; image, radios
[quix0rs-gnu-social.git] / lib / applicationeditform.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Form for editing an application
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Form
23  * @package   StatusNet
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/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/form.php';
35
36 /**
37  * Form for editing an application
38  *
39  * @category Form
40  * @package  StatusNet
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/
44  *
45  */
46
47 class ApplicationEditForm extends Form
48 {
49     /**
50      * group for user to join
51      */
52
53     var $application = null;
54
55     /**
56      * Constructor
57      *
58      * @param Action     $out   output channel
59      * @param User_group $group group to join
60      */
61
62     function __construct($out=null, $application=null)
63     {
64         parent::__construct($out);
65
66         $this->application = $application;
67     }
68
69     /**
70      * ID of the form
71      *
72      * @return string ID of the form
73      */
74
75     function id()
76     {
77         if ($this->application) {
78             return 'form_application_edit-' . $this->application->id;
79         } else {
80             return 'form_application_add';
81         }
82     }
83
84     /**
85      * HTTP method used to submit the form
86      *
87      * For image data we need to send multipart/form-data
88      * so we set that here too
89      *
90      * @return string the method to use for submitting
91      */
92
93     function method()
94     {
95         $this->enctype = 'multipart/form-data';
96         return 'post';
97     }
98
99     /**
100      * class of the form
101      *
102      * @return string of the form class
103      */
104
105     function formClass()
106     {
107         return 'form_settings';
108     }
109
110     /**
111      * Action of the form
112      *
113      * @return string URL of the action
114      */
115
116     function action()
117     {
118         $cur = common_current_user();
119
120         if (!empty($this->application)) {
121             return common_local_url('editapplication',
122                 array('id' => $this->application->id,
123                       'nickname' => $cur->nickname)
124             );
125         } else {
126             return common_local_url('newapplication',
127                 array('nickname' => $cur->nickname));
128         }
129     }
130
131     /**
132      * Name of the form
133      *
134      * @return void
135      */
136
137     function formLegend()
138     {
139         $this->out->element('legend', null, _('Edit application'));
140     }
141
142     /**
143      * Data elements of the form
144      *
145      * @return void
146      */
147
148     function formData()
149     {
150         if ($this->application) {
151             $id                = $this->application->id;
152             $icon              = $this->application->icon;
153             $name              = $this->application->name;
154             $description       = $this->application->description;
155             $source_url        = $this->application->source_url;
156             $organization      = $this->application->organization;
157             $homepage          = $this->application->homepage;
158             $callback_url      = $this->application->callback_url;
159             $this->type        = $this->application->type;
160             $this->access_type = $this->application->access_type;
161         } else {
162             $id                = '';
163             $icon              = '';
164             $name              = '';
165             $description       = '';
166             $source_url        = '';
167             $organization      = '';
168             $homepage          = '';
169             $callback_url      = '';
170             $this->type        = '';
171             $this->access_type = '';
172         }
173
174         $this->out->hidden('token', common_session_token());
175
176         $this->out->elementStart('ul', 'form_data');
177
178         $this->out->elementStart('li', array('id' => 'application_icon'));
179
180         if (!empty($icon)) {
181             $this->out->element('img', array('src' => $icon));
182         }
183
184         $this->out->element('label', array('for' => 'app_icon'),
185                                 _('Icon'));
186         $this->out->element('input', array('name' => 'app_icon',
187                                       'type' => 'file',
188                                       'id' => 'app_icon'));
189         $this->out->element('p', 'form_guide', _('Icon for this application'));
190         $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
191                                       'type' => 'hidden',
192                                       'id' => 'MAX_FILE_SIZE',
193                                       'value' => ImageFile::maxFileSizeInt()));
194         $this->out->elementEnd('li');
195
196         $this->out->elementStart('li');
197
198         $this->out->hidden('application_id', $id);
199
200         $this->out->input('name', _('Name'),
201                           ($this->out->arg('name')) ? $this->out->arg('name') : $name);
202
203         $this->out->elementEnd('li');
204
205         $this->out->elementStart('li');
206
207         $maxDesc = Oauth_application::maxDesc();
208         if ($maxDesc > 0) {
209             $descInstr = sprintf(_('Describe your application in %d chars'),
210                                 $maxDesc);
211         } else {
212             $descInstr = _('Describe your application');
213         }
214         $this->out->textarea('description', _('Description'),
215                         ($this->out->arg('description')) ? $this->out->arg('description') : $description,
216                         $descInstr);
217
218         $this->out->elementEnd('li');
219
220         $this->out->elementStart('li');
221         $this->out->input('source_url', _('Source URL'),
222                           ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
223                           _('URL of the homepage of this application'));
224         $this->out->elementEnd('li');
225
226         $this->out->elementStart('li');
227         $this->out->input('organization', _('Organization'),
228                           ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
229                           _('Organization responsible for this application'));
230         $this->out->elementEnd('li');
231
232         $this->out->elementStart('li');
233         $this->out->input('homepage', _('Homepage'),
234                           ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
235                           _('URL for the homepage of the organization'));
236         $this->out->elementEnd('li');
237
238         $this->out->elementStart('li');
239         $this->out->input('callback_url', ('Callback URL'),
240                           ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
241                           _('URL to redirect to after authentication'));
242         $this->out->elementEnd('li');
243
244         $this->out->elementStart('li', array('id' => 'application_types'));
245
246         $attrs = array('name' => 'app_type',
247                        'type' => 'radio',
248                        'id' => 'app_type-browser',
249                        'class' => 'radio',
250                        'value' => Oauth_application::$browser);
251
252         // Default to Browser
253
254         if ($this->application->type == Oauth_application::$browser
255             || empty($this->application->type)) {
256             $attrs['checked'] = 'checked';
257         }
258
259         $this->out->element('input', $attrs);
260
261         $this->out->element('label', array('for' => 'app_type-browser',
262                                       'class' => 'radio'),
263                                       _('Browser'));
264
265         $attrs = array('name' => 'app_type',
266                        'type' => 'radio',
267                        'id' => 'app_type-dekstop',
268                        'class' => 'radio',
269                        'value' => Oauth_application::$desktop);
270
271         if ($this->application->type == Oauth_application::$desktop) {
272             $attrs['checked'] = 'checked';
273         }
274
275         $this->out->element('input', $attrs);
276
277         $this->out->element('label', array('for' => 'app_type-desktop',
278                                       'class' => 'radio'),
279                                       _('Desktop'));
280         $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
281         $this->out->elementEnd('li');
282
283         $this->out->elementStart('li', array('id' => 'default_access_types'));
284
285         $attrs = array('name' => 'default_access_type',
286                        'type' => 'radio',
287                        'id' => 'default_access_type-r',
288                        'class' => 'radio',
289                        'value' => 'r');
290
291         // default to read-only access
292
293         if ($this->application->access_type & Oauth_application::$readAccess
294             || empty($this->application->access_type)) {
295             $attrs['checked'] = 'checked';
296         }
297
298         $this->out->element('input', $attrs);
299
300         $this->out->element('label', array('for' => 'default_access_type-ro',
301                                       'class' => 'radio'),
302                                       _('Read-only'));
303
304         $attrs = array('name' => 'default_access_type',
305                        'type' => 'radio',
306                        'id' => 'default_access_type-rw',
307                        'class' => 'radio',
308                        'value' => 'rw');
309
310         if ($this->application->access_type & Oauth_application::$readAccess
311             && $this->application->access_type & Oauth_application::$writeAccess
312         ) {
313             $attrs['checked'] = 'checked';
314         }
315
316         $this->out->element('input', $attrs);
317
318         $this->out->element('label', array('for' => 'default_access_type-rw',
319                                       'class' => 'radio'),
320                                       _('Read-write'));
321         $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
322
323         $this->out->elementEnd('li');
324
325         $this->out->elementEnd('ul');
326     }
327
328     /**
329      * Action elements
330      *
331      * @return void
332      */
333
334     function formActions()
335     {
336         $this->out->submit('cancel', _('Cancel'), 'submit form_action-primary',
337             'cancel', _('Cancel'));
338         $this->out->submit('save', _('Save'), 'submit form_action-secondary',
339             'save', _('Save'));
340     }
341 }