]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationeditform.php
* update/add translator documentation
[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 class ApplicationEditForm extends Form
47 {
48     /**
49      * group for user to join
50      */
51     var $application = null;
52
53     /**
54      * Constructor
55      *
56      * @param Action     $out   output channel
57      * @param User_group $group group to join
58      */
59     function __construct($out=null, $application=null)
60     {
61         parent::__construct($out);
62
63         $this->application = $application;
64     }
65
66     /**
67      * ID of the form
68      *
69      * @return string ID of the form
70      */
71     function id()
72     {
73         if ($this->application) {
74             return 'form_application_edit-' . $this->application->id;
75         } else {
76             return 'form_application_add';
77         }
78     }
79
80     /**
81      * HTTP method used to submit the form
82      *
83      * For image data we need to send multipart/form-data
84      * so we set that here too
85      *
86      * @return string the method to use for submitting
87      */
88     function method()
89     {
90         $this->enctype = 'multipart/form-data';
91         return 'post';
92     }
93
94     /**
95      * class of the form
96      *
97      * @return string of the form class
98      */
99     function formClass()
100     {
101         return 'form_settings';
102     }
103
104     /**
105      * Action of the form
106      *
107      * @return string URL of the action
108      */
109     function action()
110     {
111         $cur = common_current_user();
112
113         if (!empty($this->application)) {
114             return common_local_url('editapplication',
115                                     array('id' => $this->application->id));
116         } else {
117             return common_local_url('newapplication');
118         }
119     }
120
121     /**
122      * Name of the form
123      *
124      * @return void
125      */
126     function formLegend()
127     {
128         // TRANS: Form legend.
129         $this->out->element('legend', null, _('Edit application'));
130     }
131
132     /**
133      * Data elements of the form
134      *
135      * @return void
136      */
137     function formData()
138     {
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;
150         } else {
151             $id                = '';
152             $icon              = '';
153             $name              = '';
154             $description       = '';
155             $source_url        = '';
156             $organization      = '';
157             $homepage          = '';
158             $callback_url      = '';
159             $this->type        = '';
160             $this->access_type = '';
161         }
162
163         $this->out->elementStart('ul', 'form_data');
164
165         $this->out->elementStart('li', array('id' => 'application_icon'));
166
167         if (!empty($icon)) {
168             $this->out->element('img', array('src' => $icon));
169         }
170
171         $this->out->element('label', array('for' => 'app_icon'),
172                             // TRANS: Form input field label for application icon.
173                             _('Icon'));
174         $this->out->element('input', array('name' => 'app_icon',
175                                            'type' => 'file',
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',
180                                            'type' => 'hidden',
181                                            'id' => 'MAX_FILE_SIZE',
182                                            'value' => ImageFile::maxFileSizeInt()));
183         $this->out->elementEnd('li');
184
185         $this->out->elementStart('li');
186
187         $this->out->hidden('application_id', $id);
188
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);
192
193         $this->out->elementEnd('li');
194
195         $this->out->elementStart('li');
196
197         $maxDesc = Oauth_application::maxDesc();
198         if ($maxDesc > 0) {
199             // TRANS: Form input field instructions.
200             $descInstr = sprintf(_('Describe your application in %d characters'),
201                                  $maxDesc);
202         } else {
203             // TRANS: Form input field instructions.
204             $descInstr = _('Describe your application');
205         }
206         // TRANS: Form input field label.
207         $this->out->textarea('description', _('Description'),
208                         ($this->out->arg('description')) ? $this->out->arg('description') : $description,
209                              $descInstr);
210
211         $this->out->elementEnd('li');
212
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,
219                           $instruction);
220         $this->out->elementEnd('li');
221
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,
228                           $instruction);
229         $this->out->elementEnd('li');
230
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,
237                           $instruction);
238         $this->out->elementEnd('li');
239
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,
246                           $instruction);
247         $this->out->elementEnd('li');
248
249         $this->out->elementStart('li', array('id' => 'application_types'));
250
251         $attrs = array('name' => 'app_type',
252                        'type' => 'radio',
253                        'id' => 'app_type-browser',
254                        'class' => 'radio',
255                        'value' => Oauth_application::$browser);
256
257         // Default to Browser
258
259         if ($this->application->type == Oauth_application::$browser
260             || empty($this->application->type)) {
261             $attrs['checked'] = 'checked';
262         }
263
264         $this->out->element('input', $attrs);
265
266         $this->out->element('label', array('for' => 'app_type-browser',
267                                            'class' => 'radio'),
268                             // TRANS: Radio button label for application type
269                             _('Browser'));
270
271         $attrs = array('name' => 'app_type',
272                        'type' => 'radio',
273                        'id' => 'app_type-dekstop',
274                        'class' => 'radio',
275                        'value' => Oauth_application::$desktop);
276
277         if ($this->application->type == Oauth_application::$desktop) {
278             $attrs['checked'] = 'checked';
279         }
280
281         $this->out->element('input', $attrs);
282
283         $this->out->element('label', array('for' => 'app_type-desktop',
284                                            'class' => 'radio'),
285                             // TRANS: Radio button label for application type
286                             _('Desktop'));
287         // TRANS: Form guide.
288         $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
289         $this->out->elementEnd('li');
290
291         $this->out->elementStart('li', array('id' => 'default_access_types'));
292
293         $attrs = array('name' => 'default_access_type',
294                        'type' => 'radio',
295                        'id' => 'default_access_type-r',
296                        'class' => 'radio',
297                        'value' => 'r');
298
299         // default to read-only access
300
301         if ($this->application->access_type & Oauth_application::$readAccess
302             || empty($this->application->access_type)) {
303             $attrs['checked'] = 'checked';
304         }
305
306         $this->out->element('input', $attrs);
307
308         $this->out->element('label', array('for' => 'default_access_type-ro',
309                                            'class' => 'radio'),
310                             // TRANS: Radio button label for access type.
311                             _('Read-only'));
312
313         $attrs = array('name' => 'default_access_type',
314                        'type' => 'radio',
315                        'id' => 'default_access_type-rw',
316                        'class' => 'radio',
317                        'value' => 'rw');
318
319         if ($this->application->access_type & Oauth_application::$readAccess
320             && $this->application->access_type & Oauth_application::$writeAccess
321             ) {
322             $attrs['checked'] = 'checked';
323         }
324
325         $this->out->element('input', $attrs);
326
327         $this->out->element('label', array('for' => 'default_access_type-rw',
328                                            'class' => 'radio'),
329                             // TRANS: Radio button label for access type.
330                             _('Read-write'));
331         // TRANS: Form guide.
332         $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
333
334         $this->out->elementEnd('li');
335
336         $this->out->elementEnd('ul');
337     }
338
339     /**
340      * Action elements
341      *
342      * @return void
343      */
344     function formActions()
345     {
346         // TRANS: Button label in the "Edit application" form.
347         $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
348                            // TRANS: Submit button title.
349                            'cancel', _('Cancel'));
350         // TRANS: Button label in the "Edit application" form.
351         $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
352                            // TRANS: Submit button title.
353                            'save', _('Save'));
354     }
355 }