]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/applicationeditform.php
ed187ba0b4e402b2aeeecb31b78c559476660b3b
[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      * class of the form
86      *
87      * @return string of the form class
88      */
89
90     function formClass()
91     {
92         return 'form_settings';
93     }
94
95     /**
96      * Action of the form
97      *
98      * @return string URL of the action
99      */
100
101     function action()
102     {
103         $cur = common_current_user();
104
105         if (!empty($this->application)) {
106             return common_local_url('editapplication',
107                 array('id' => $this->application->id,
108                       'nickname' => $cur->nickname)
109             );
110         } else {
111             return common_local_url('newapplication',
112                 array('nickname' => $cur->nickname));
113         }
114     }
115
116     /**
117      * Name of the form
118      *
119      * @return void
120      */
121
122     function formLegend()
123     {
124         $this->out->element('legend', null, _('Edit application'));
125     }
126
127     /**
128      * Data elements of the form
129      *
130      * @return void
131      */
132
133     function formData()
134     {
135         if ($this->application) {
136             $id                = $this->application->id;
137             $name              = $this->application->name;
138             $description       = $this->application->description;
139             $source_url        = $this->application->source_url;
140             $organization      = $this->application->organization;
141             $homepage          = $this->application->homepage;
142             $callback_url      = $this->application->callback_url;
143             $this->type        = $this->application->type;
144             $this->access_type = $this->application->access_type;
145         } else {
146             $id                = '';
147             $name              = '';
148             $description       = '';
149             $source_url        = '';
150             $organization      = '';
151             $homepage          = '';
152             $callback_url      = '';
153             $this->type        = '';
154             $this->access_type = '';
155         }
156
157         $this->out->elementStart('ul', 'form_data');
158         $this->out->elementStart('li');
159
160         $this->out->hidden('application_id', $id);
161         $this->out->hidden('token', common_session_token());
162
163         $this->out->input('name', _('Name'),
164                           ($this->out->arg('name')) ? $this->out->arg('name') : $name);
165
166         $this->out->elementEnd('li');
167
168         $this->out->elementStart('li');
169
170         $maxDesc = Oauth_application::maxDesc();
171         if ($maxDesc > 0) {
172             $descInstr = sprintf(_('Describe your application in %d chars'),
173                                 $maxDesc);
174         } else {
175             $descInstr = _('Describe your application');
176         }
177         $this->out->textarea('description', _('Description'),
178                         ($this->out->arg('description')) ? $this->out->arg('description') : $description,
179                         $descInstr);
180
181         $this->out->elementEnd('li');
182
183         $this->out->elementStart('li');
184         $this->out->input('source_url', _('Source URL'),
185                           ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
186                           _('URL of the homepage of this application'));
187         $this->out->elementEnd('li');
188
189         $this->out->elementStart('li');
190         $this->out->input('organization', _('Organization'),
191                           ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
192                           _('Organization responsible for this application'));
193         $this->out->elementEnd('li');
194
195         $this->out->elementStart('li');
196         $this->out->input('homepage', _('Homepage'),
197                           ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
198                           _('URL for the homepage of the organization'));
199         $this->out->elementEnd('li');
200
201         $this->out->elementStart('li');
202         $this->out->input('callback_url', ('Callback URL'),
203                           ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
204                           _('URL to redirect to after authentication'));
205         $this->out->elementEnd('li');
206
207         $this->out->elementStart('li');
208
209         $attrs = array('name' => 'app_type',
210                        'type' => 'radio',
211                        'id' => 'app_type-browser',
212                        'class' => 'radio',
213                        'value' => Oauth_application::$browser);
214
215         // Default to Browser
216
217         if ($this->application->type == Oauth_application::$browser
218             || empty($this->applicaiton->type)) {
219             $attrs['checked'] = 'checked';
220         }
221
222         $this->out->element('input', $attrs);
223
224         $this->out->element('label', array('for' => 'app_type-browser',
225                                       'class' => 'radio'),
226                                       _('Browser'));
227
228         $attrs = array('name' => 'app_type',
229                        'type' => 'radio',
230                        'id' => 'app_type-dekstop',
231                        'class' => 'radio',
232                        'value' => Oauth_application::$desktop);
233
234         if ($this->application->type == Oauth_application::$desktop) {
235             $attrs['checked'] = 'checked';
236         }
237
238         $this->out->element('input', $attrs);
239
240         $this->out->element('label', array('for' => 'app_type-desktop',
241                                       'class' => 'radio'),
242                                       _('Desktop'));
243         $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
244         $this->out->elementEnd('li');
245
246         $this->out->elementStart('li');
247
248         $attrs = array('name' => 'default_access_type',
249                        'type' => 'radio',
250                        'id' => 'default_access_type-r',
251                        'class' => 'radio',
252                        'value' => 'r');
253
254         // default to read-only access
255
256         if ($this->application->access_type & Oauth_application::$readAccess
257             || empty($this->application->access_type)) {
258             $attrs['checked'] = 'checked';
259         }
260
261         $this->out->element('input', $attrs);
262
263         $this->out->element('label', array('for' => 'default_access_type-ro',
264                                       'class' => 'radio'),
265                                       _('Read-only'));
266
267         $attrs = array('name' => 'default_access_type',
268                        'type' => 'radio',
269                        'id' => 'default_access_type-rw',
270                        'class' => 'radio',
271                        'value' => 'rw');
272
273         if ($this->application->access_type & Oauth_application::$readAccess
274             && $this->application->access_type & Oauth_application::$writeAccess
275         ) {
276             $attrs['checked'] = 'checked';
277         }
278
279         $this->out->element('input', $attrs);
280
281         $this->out->element('label', array('for' => 'default_access_type-rw',
282                                       'class' => 'radio'),
283                                       _('Read-write'));
284         $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
285
286         $this->out->elementEnd('li');
287
288         $this->out->elementEnd('ul');
289     }
290
291     /**
292      * Action elements
293      *
294      * @return void
295      */
296
297     function formActions()
298     {
299         $this->out->submit('save', _('Save'));
300         $this->out->submit('cancel', _('Cancel'));
301     }
302 }