]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationeditform.php
fix notices in dumpschema
[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             // 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),
202                                  $maxDesc);
203         } else {
204             // TRANS: Form input field instructions.
205             $descInstr = _('Describe your application');
206         }
207         // TRANS: Form input field label.
208         $this->out->textarea('description', _('Description'),
209                         ($this->out->arg('description')) ? $this->out->arg('description') : $description,
210                              $descInstr);
211
212         $this->out->elementEnd('li');
213
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,
220                           $instruction);
221         $this->out->elementEnd('li');
222
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,
229                           $instruction);
230         $this->out->elementEnd('li');
231
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,
238                           $instruction);
239         $this->out->elementEnd('li');
240
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,
247                           $instruction);
248         $this->out->elementEnd('li');
249
250         $this->out->elementStart('li', array('id' => 'application_types'));
251
252         $attrs = array('name' => 'app_type',
253                        'type' => 'radio',
254                        'id' => 'app_type-browser',
255                        'class' => 'radio',
256                        'value' => Oauth_application::$browser);
257
258         // Default to Browser
259
260         if (empty($this->application)
261             || empty($this->application->type)
262             || $this->application->type == Oauth_application::$browser) {
263             $attrs['checked'] = 'checked';
264         }
265
266         $this->out->element('input', $attrs);
267
268         $this->out->element('label', array('for' => 'app_type-browser',
269                                            'class' => 'radio'),
270                             // TRANS: Radio button label for application type
271                             _('Browser'));
272
273         $attrs = array('name' => 'app_type',
274                        'type' => 'radio',
275                        'id' => 'app_type-dekstop',
276                        'class' => 'radio',
277                        'value' => Oauth_application::$desktop);
278
279         if (!empty($this->application) && $this->application->type == Oauth_application::$desktop) {
280             $attrs['checked'] = 'checked';
281         }
282
283         $this->out->element('input', $attrs);
284
285         $this->out->element('label', array('for' => 'app_type-desktop',
286                                            'class' => 'radio'),
287                             // TRANS: Radio button label for application type
288                             _('Desktop'));
289         // TRANS: Form guide.
290         $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
291         $this->out->elementEnd('li');
292
293         $this->out->elementStart('li', array('id' => 'default_access_types'));
294
295         $attrs = array('name' => 'default_access_type',
296                        'type' => 'radio',
297                        'id' => 'default_access_type-r',
298                        'class' => 'radio',
299                        'value' => 'r');
300
301         // default to read-only access
302
303         if (empty($this->application)
304             || empty($this->application->access_type)
305             || $this->application->access_type & Oauth_application::$readAccess) {
306             $attrs['checked'] = 'checked';
307         }
308
309         $this->out->element('input', $attrs);
310
311         $this->out->element('label', array('for' => 'default_access_type-ro',
312                                            'class' => 'radio'),
313                             // TRANS: Radio button label for access type.
314                             _('Read-only'));
315
316         $attrs = array('name' => 'default_access_type',
317                        'type' => 'radio',
318                        'id' => 'default_access_type-rw',
319                        'class' => 'radio',
320                        'value' => 'rw');
321
322         if (!empty($this->application)
323             && $this->application->access_type & Oauth_application::$readAccess
324             && $this->application->access_type & Oauth_application::$writeAccess
325             ) {
326             $attrs['checked'] = 'checked';
327         }
328
329         $this->out->element('input', $attrs);
330
331         $this->out->element('label', array('for' => 'default_access_type-rw',
332                                            'class' => 'radio'),
333                             // TRANS: Radio button label for access type.
334                             _('Read-write'));
335         // TRANS: Form guide.
336         $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
337
338         $this->out->elementEnd('li');
339
340         $this->out->elementEnd('ul');
341     }
342
343     /**
344      * Action elements
345      *
346      * @return void
347      */
348     function formActions()
349     {
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.
357                            'save', _('Save'));
358     }
359 }