We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

applicationeditform.php 12.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Form for editing an application
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Form
 * @package   StatusNet
 * @author    Zach Copley <zach@status.net>
 * @copyright 2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

require_once INSTALLDIR . '/lib/form.php';

/**
 * Form for editing an application
 *
 * @category Form
 * @package  StatusNet
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 *
 */

class ApplicationEditForm extends Form
{
    /**
     * group for user to join
     */

    var $application = null;

    /**
     * Constructor
     *
     * @param Action     $out   output channel
     * @param User_group $group group to join
     */

    function __construct($out=null, $application=null)
    {
        parent::__construct($out);

        $this->application = $application;
    }

    /**
     * ID of the form
     *
     * @return string ID of the form
     */

    function id()
    {
        if ($this->application) {
            return 'form_application_edit-' . $this->application->id;
        } else {
            return 'form_application_add';
        }
    }

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    /**
     * HTTP method used to submit the form
     *
     * For image data we need to send multipart/form-data
     * so we set that here too
     *
     * @return string the method to use for submitting
     */

    function method()
    {
        $this->enctype = 'multipart/form-data';
        return 'post';
    }

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    /**
     * class of the form
     *
     * @return string of the form class
     */

    function formClass()
    {
        return 'form_settings';
    }

    /**
     * Action of the form
     *
     * @return string URL of the action
     */

    function action()
    {
118 119 120
        $cur = common_current_user();

        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 130 131 132 133 134 135
        }
    }

    /**
     * Name of the form
     *
     * @return void
     */

    function formLegend()
    {
136
        // TRANS: Form legend.
137
        $this->out->element('legend', null, _('Edit application'));
138 139 140 141 142 143 144 145 146 147 148 149
    }

    /**
     * Data elements of the form
     *
     * @return void
     */

    function formData()
    {
        if ($this->application) {
            $id                = $this->application->id;
150
            $icon              = $this->application->icon;
151
            $name              = $this->application->name;
152
            $description       = $this->application->description;
153 154 155 156 157 158 159 160
            $source_url        = $this->application->source_url;
            $organization      = $this->application->organization;
            $homepage          = $this->application->homepage;
            $callback_url      = $this->application->callback_url;
            $this->type        = $this->application->type;
            $this->access_type = $this->application->access_type;
        } else {
            $id                = '';
161
            $icon              = '';
162 163 164 165 166 167 168 169 170 171 172
            $name              = '';
            $description       = '';
            $source_url        = '';
            $organization      = '';
            $homepage          = '';
            $callback_url      = '';
            $this->type        = '';
            $this->access_type = '';
        }

        $this->out->elementStart('ul', 'form_data');
173

174
        $this->out->elementStart('li', array('id' => 'application_icon'));
175

176 177 178
        if (!empty($icon)) {
            $this->out->element('img', array('src' => $icon));
        }
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 185
                                           'type' => 'file',
                                           'id' => 'app_icon'));
186
        // TRANS: Form guide.
187 188
        $this->out->element('p', 'form_guide', _('Icon for this application'));
        $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
189 190 191
                                           'type' => 'hidden',
                                           'id' => 'MAX_FILE_SIZE',
                                           'value' => ImageFile::maxFileSizeInt()));
192 193
        $this->out->elementEnd('li');

194
        $this->out->elementStart('li');
195

196
        $this->out->hidden('application_id', $id);
197

198
        // TRANS: Form input field label for application name.
199 200
        $this->out->input('name', _('Name'),
                          ($this->out->arg('name')) ? $this->out->arg('name') : $name);
201

202
        $this->out->elementEnd('li');
203

204
        $this->out->elementStart('li');
205 206 207

        $maxDesc = Oauth_application::maxDesc();
        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 214
            $descInstr = _('Describe your application');
        }
215
        // TRANS: Form input field label.
216 217
        $this->out->textarea('description', _('Description'),
                        ($this->out->arg('description')) ? $this->out->arg('description') : $description,
218
                             $descInstr);
219

220
        $this->out->elementEnd('li');
221

222
        $this->out->elementStart('li');
223 224 225
        // TRANS: Form input field instructions.
        $instruction = _('URL of the homepage of this application');
        // TRANS: Form input field label.
226 227
        $this->out->input('source_url', _('Source URL'),
                          ($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 233 234
        // TRANS: Form input field instructions.
        $instruction = _('Organization responsible for this application');
        // TRANS: Form input field label.
235 236
        $this->out->input('organization', _('Organization'),
                          ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
237
                          $instruction);
238 239 240
        $this->out->elementEnd('li');

        $this->out->elementStart('li');
241 242 243
        // TRANS: Form input field instructions.
        $instruction = _('URL for the homepage of the organization');
        // TRANS: Form input field label.
244 245
        $this->out->input('homepage', _('Homepage'),
                          ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
246
                          $instruction);
247 248 249
        $this->out->elementEnd('li');

        $this->out->elementStart('li');
250 251 252
        // TRANS: Form input field instructions.
        $instruction = _('URL to redirect to after authentication');
        // TRANS: Form input field label.
253 254
        $this->out->input('callback_url', ('Callback URL'),
                          ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
255
                          $instruction);
256 257
        $this->out->elementEnd('li');

258
        $this->out->elementStart('li', array('id' => 'application_types'));
259 260 261 262 263 264 265 266 267 268

        $attrs = array('name' => 'app_type',
                       'type' => 'radio',
                       'id' => 'app_type-browser',
                       'class' => 'radio',
                       'value' => Oauth_application::$browser);

        // Default to Browser

        if ($this->application->type == Oauth_application::$browser
269
            || empty($this->application->type)) {
270 271 272 273 274 275
            $attrs['checked'] = 'checked';
        }

        $this->out->element('input', $attrs);

        $this->out->element('label', array('for' => 'app_type-browser',
276
                                           'class' => 'radio'),
277
                            // TRANS: Radio button label for application type
278
                            _('Browser'));
279 280 281 282 283 284 285 286 287 288 289 290 291 292

        $attrs = array('name' => 'app_type',
                       'type' => 'radio',
                       'id' => 'app_type-dekstop',
                       'class' => 'radio',
                       'value' => Oauth_application::$desktop);

        if ($this->application->type == Oauth_application::$desktop) {
            $attrs['checked'] = 'checked';
        }

        $this->out->element('input', $attrs);

        $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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317

        $attrs = array('name' => 'default_access_type',
                       'type' => 'radio',
                       'id' => 'default_access_type-r',
                       'class' => 'radio',
                       'value' => 'r');

        // default to read-only access

        if ($this->application->access_type & Oauth_application::$readAccess
            || empty($this->application->access_type)) {
            $attrs['checked'] = 'checked';
        }

        $this->out->element('input', $attrs);

        $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 323 324 325 326 327 328 329

        $attrs = array('name' => 'default_access_type',
                       'type' => 'radio',
                       'id' => 'default_access_type-rw',
                       'class' => 'radio',
                       'value' => 'rw');

        if ($this->application->access_type & Oauth_application::$readAccess
            && $this->application->access_type & Oauth_application::$writeAccess
330
            ) {
331 332 333 334 335 336
            $attrs['checked'] = 'checked';
        }

        $this->out->element('input', $attrs);

        $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 342
        $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));

343
        $this->out->elementEnd('li');
344

345 346 347 348 349 350 351 352 353 354 355
        $this->out->elementEnd('ul');
    }

    /**
     * Action elements
     *
     * @return void
     */

    function formActions()
    {
356 357 358
        // TRANS: Button label
        $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
                           // TRANS: Submit button title
359
                           'cancel', _('Cancel'));
360 361 362
        // TRANS: Button label
        $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
                           // TRANS: Submit button title
363
                           'save', _('Save'));
364 365
    }
}