]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationeditform.php
Merge remote branch 'gitorious/0.9.x' 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 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 (empty($this->application)
260             || empty($this->application->type)
261             || $this->application->type == Oauth_application::$browser) {
262             $attrs['checked'] = 'checked';
263         }
264
265         $this->out->element('input', $attrs);
266
267         $this->out->element('label', array('for' => 'app_type-browser',
268                                            'class' => 'radio'),
269                             // TRANS: Radio button label for application type
270                             _('Browser'));
271
272         $attrs = array('name' => 'app_type',
273                        'type' => 'radio',
274                        'id' => 'app_type-dekstop',
275                        'class' => 'radio',
276                        'value' => Oauth_application::$desktop);
277
278         if (!empty($this->application) && $this->application->type == Oauth_application::$desktop) {
279             $attrs['checked'] = 'checked';
280         }
281
282         $this->out->element('input', $attrs);
283
284         $this->out->element('label', array('for' => 'app_type-desktop',
285                                            'class' => 'radio'),
286                             // TRANS: Radio button label for application type
287                             _('Desktop'));
288         // TRANS: Form guide.
289         $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
290         $this->out->elementEnd('li');
291
292         $this->out->elementStart('li', array('id' => 'default_access_types'));
293
294         $attrs = array('name' => 'default_access_type',
295                        'type' => 'radio',
296                        'id' => 'default_access_type-r',
297                        'class' => 'radio',
298                        'value' => 'r');
299
300         // default to read-only access
301
302         if (empty($this->application)
303             || empty($this->application->access_type)
304             || $this->application->access_type & Oauth_application::$readAccess) {
305             $attrs['checked'] = 'checked';
306         }
307
308         $this->out->element('input', $attrs);
309
310         $this->out->element('label', array('for' => 'default_access_type-ro',
311                                            'class' => 'radio'),
312                             // TRANS: Radio button label for access type.
313                             _('Read-only'));
314
315         $attrs = array('name' => 'default_access_type',
316                        'type' => 'radio',
317                        'id' => 'default_access_type-rw',
318                        'class' => 'radio',
319                        'value' => 'rw');
320
321         if (!empty($this->application)
322             && $this->application->access_type & Oauth_application::$readAccess
323             && $this->application->access_type & Oauth_application::$writeAccess
324             ) {
325             $attrs['checked'] = 'checked';
326         }
327
328         $this->out->element('input', $attrs);
329
330         $this->out->element('label', array('for' => 'default_access_type-rw',
331                                            'class' => 'radio'),
332                             // TRANS: Radio button label for access type.
333                             _('Read-write'));
334         // TRANS: Form guide.
335         $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
336
337         $this->out->elementEnd('li');
338
339         $this->out->elementEnd('ul');
340     }
341
342     /**
343      * Action elements
344      *
345      * @return void
346      */
347     function formActions()
348     {
349         // TRANS: Button label in the "Edit application" form.
350         $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
351                            // TRANS: Submit button title.
352                            'cancel', _('Cancel'));
353         // TRANS: Button label in the "Edit application" form.
354         $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
355                            // TRANS: Submit button title.
356                            'save', _('Save'));
357     }
358 }