]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationeditform.php
Merge branch 'testing' into 0.9.x
[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         } else {
124             return common_local_url('newapplication');
125         }
126     }
127
128     /**
129      * Name of the form
130      *
131      * @return void
132      */
133
134     function formLegend()
135     {
136         // TRANS: Form legend.
137         $this->out->element('legend', null, _('Edit application'));
138     }
139
140     /**
141      * Data elements of the form
142      *
143      * @return void
144      */
145
146     function formData()
147     {
148         if ($this->application) {
149             $id                = $this->application->id;
150             $icon              = $this->application->icon;
151             $name              = $this->application->name;
152             $description       = $this->application->description;
153             $source_url        = $this->application->source_url;
154             $organization      = $this->application->organization;
155             $homepage          = $this->application->homepage;
156             $callback_url      = $this->application->callback_url;
157             $this->type        = $this->application->type;
158             $this->access_type = $this->application->access_type;
159         } else {
160             $id                = '';
161             $icon              = '';
162             $name              = '';
163             $description       = '';
164             $source_url        = '';
165             $organization      = '';
166             $homepage          = '';
167             $callback_url      = '';
168             $this->type        = '';
169             $this->access_type = '';
170         }
171
172         $this->out->elementStart('ul', 'form_data');
173
174         $this->out->elementStart('li', array('id' => 'application_icon'));
175
176         if (!empty($icon)) {
177             $this->out->element('img', array('src' => $icon));
178         }
179
180         $this->out->element('label', array('for' => 'app_icon'),
181                             // TRANS: Form input field label for application icon.
182                             _('Icon'));
183         $this->out->element('input', array('name' => 'app_icon',
184                                            'type' => 'file',
185                                            'id' => 'app_icon'));
186         // TRANS: Form guide.
187         $this->out->element('p', 'form_guide', _('Icon for this application'));
188         $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
189                                            'type' => 'hidden',
190                                            'id' => 'MAX_FILE_SIZE',
191                                            'value' => ImageFile::maxFileSizeInt()));
192         $this->out->elementEnd('li');
193
194         $this->out->elementStart('li');
195
196         $this->out->hidden('application_id', $id);
197
198         // TRANS: Form input field label for application name.
199         $this->out->input('name', _('Name'),
200                           ($this->out->arg('name')) ? $this->out->arg('name') : $name);
201
202         $this->out->elementEnd('li');
203
204         $this->out->elementStart('li');
205
206         $maxDesc = Oauth_application::maxDesc();
207         if ($maxDesc > 0) {
208             // TRANS: Form input field instructions.
209             $descInstr = sprintf(_('Describe your application in %d characters'),
210                                  $maxDesc);
211         } else {
212             // TRANS: Form input field instructions.
213             $descInstr = _('Describe your application');
214         }
215         // TRANS: Form input field label.
216         $this->out->textarea('description', _('Description'),
217                         ($this->out->arg('description')) ? $this->out->arg('description') : $description,
218                              $descInstr);
219
220         $this->out->elementEnd('li');
221
222         $this->out->elementStart('li');
223         // TRANS: Form input field instructions.
224         $instruction = _('URL of the homepage of this application');
225         // TRANS: Form input field label.
226         $this->out->input('source_url', _('Source URL'),
227                           ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
228                           $instruction);
229         $this->out->elementEnd('li');
230
231         $this->out->elementStart('li');
232         // TRANS: Form input field instructions.
233         $instruction = _('Organization responsible for this application');
234         // TRANS: Form input field label.
235         $this->out->input('organization', _('Organization'),
236                           ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
237                           $instruction);
238         $this->out->elementEnd('li');
239
240         $this->out->elementStart('li');
241         // TRANS: Form input field instructions.
242         $instruction = _('URL for the homepage of the organization');
243         // TRANS: Form input field label.
244         $this->out->input('homepage', _('Homepage'),
245                           ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
246                           $instruction);
247         $this->out->elementEnd('li');
248
249         $this->out->elementStart('li');
250         // TRANS: Form input field instructions.
251         $instruction = _('URL to redirect to after authentication');
252         // TRANS: Form input field label.
253         $this->out->input('callback_url', ('Callback URL'),
254                           ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
255                           $instruction);
256         $this->out->elementEnd('li');
257
258         $this->out->elementStart('li', array('id' => 'application_types'));
259
260         $attrs = array('name' => 'app_type',
261                        'type' => 'radio',
262                        'id' => 'app_type-browser',
263                        'class' => 'radio',
264                        'value' => Oauth_application::$browser);
265
266         // Default to Browser
267
268         if ($this->application->type == Oauth_application::$browser
269             || empty($this->application->type)) {
270             $attrs['checked'] = 'checked';
271         }
272
273         $this->out->element('input', $attrs);
274
275         $this->out->element('label', array('for' => 'app_type-browser',
276                                            'class' => 'radio'),
277                             // TRANS: Radio button label for application type
278                             _('Browser'));
279
280         $attrs = array('name' => 'app_type',
281                        'type' => 'radio',
282                        'id' => 'app_type-dekstop',
283                        'class' => 'radio',
284                        'value' => Oauth_application::$desktop);
285
286         if ($this->application->type == Oauth_application::$desktop) {
287             $attrs['checked'] = 'checked';
288         }
289
290         $this->out->element('input', $attrs);
291
292         $this->out->element('label', array('for' => 'app_type-desktop',
293                                            'class' => 'radio'),
294                             // TRANS: Radio button label for application type
295                             _('Desktop'));
296         // TRANS: Form guide.
297         $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
298         $this->out->elementEnd('li');
299
300         $this->out->elementStart('li', array('id' => 'default_access_types'));
301
302         $attrs = array('name' => 'default_access_type',
303                        'type' => 'radio',
304                        'id' => 'default_access_type-r',
305                        'class' => 'radio',
306                        'value' => 'r');
307
308         // default to read-only access
309
310         if ($this->application->access_type & Oauth_application::$readAccess
311             || empty($this->application->access_type)) {
312             $attrs['checked'] = 'checked';
313         }
314
315         $this->out->element('input', $attrs);
316
317         $this->out->element('label', array('for' => 'default_access_type-ro',
318                                            'class' => 'radio'),
319                             // TRANS: Radio button label for access type.
320                             _('Read-only'));
321
322         $attrs = array('name' => 'default_access_type',
323                        'type' => 'radio',
324                        'id' => 'default_access_type-rw',
325                        'class' => 'radio',
326                        'value' => 'rw');
327
328         if ($this->application->access_type & Oauth_application::$readAccess
329             && $this->application->access_type & Oauth_application::$writeAccess
330             ) {
331             $attrs['checked'] = 'checked';
332         }
333
334         $this->out->element('input', $attrs);
335
336         $this->out->element('label', array('for' => 'default_access_type-rw',
337                                            'class' => 'radio'),
338                             // TRANS: Radio button label for access type.
339                             _('Read-write'));
340         // TRANS: Form guide.
341         $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
342
343         $this->out->elementEnd('li');
344
345         $this->out->elementEnd('ul');
346     }
347
348     /**
349      * Action elements
350      *
351      * @return void
352      */
353
354     function formActions()
355     {
356         // TRANS: Button label
357         $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
358                            // TRANS: Submit button title
359                            'cancel', _('Cancel'));
360         // TRANS: Button label
361         $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
362                            // TRANS: Submit button title
363                            'save', _('Save'));
364     }
365 }