2009-11-14 03:02:18 +00:00
|
|
|
<?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';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-07 09:55:57 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
}
|
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
2009-11-17 00:58:49 +00:00
|
|
|
$cur = common_current_user();
|
|
|
|
|
|
|
|
if (!empty($this->application)) {
|
2009-11-14 03:02:18 +00:00
|
|
|
return common_local_url('editapplication',
|
2010-01-13 07:33:51 +00:00
|
|
|
array('id' => $this->application->id));
|
2009-11-14 03:02:18 +00:00
|
|
|
} else {
|
2010-01-13 07:33:51 +00:00
|
|
|
return common_local_url('newapplication');
|
2009-11-14 03:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the form
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function formLegend()
|
|
|
|
{
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form legend.
|
2009-11-17 00:58:49 +00:00
|
|
|
$this->out->element('legend', null, _('Edit application'));
|
2009-11-14 03:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data elements of the form
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function formData()
|
|
|
|
{
|
|
|
|
if ($this->application) {
|
|
|
|
$id = $this->application->id;
|
2010-01-13 07:33:51 +00:00
|
|
|
$icon = $this->application->icon;
|
2009-11-14 03:02:18 +00:00
|
|
|
$name = $this->application->name;
|
2009-11-17 00:58:49 +00:00
|
|
|
$description = $this->application->description;
|
2009-11-14 03:02:18 +00:00
|
|
|
$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 = '';
|
2010-01-13 07:33:51 +00:00
|
|
|
$icon = '';
|
2009-11-14 03:02:18 +00:00
|
|
|
$name = '';
|
|
|
|
$description = '';
|
|
|
|
$source_url = '';
|
|
|
|
$organization = '';
|
|
|
|
$homepage = '';
|
|
|
|
$callback_url = '';
|
|
|
|
$this->type = '';
|
|
|
|
$this->access_type = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->out->elementStart('ul', 'form_data');
|
2010-01-07 09:55:57 +00:00
|
|
|
|
2010-01-13 07:33:51 +00:00
|
|
|
$this->out->elementStart('li', array('id' => 'application_icon'));
|
2010-01-07 09:55:57 +00:00
|
|
|
|
2010-01-13 07:33:51 +00:00
|
|
|
if (!empty($icon)) {
|
|
|
|
$this->out->element('img', array('src' => $icon));
|
|
|
|
}
|
2010-01-07 09:55:57 +00:00
|
|
|
|
2010-01-13 07:33:51 +00:00
|
|
|
$this->out->element('label', array('for' => 'app_icon'),
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field label for application icon.
|
2010-01-13 07:33:51 +00:00
|
|
|
_('Icon'));
|
2010-01-07 09:55:57 +00:00
|
|
|
$this->out->element('input', array('name' => 'app_icon',
|
2010-01-13 07:33:51 +00:00
|
|
|
'type' => 'file',
|
|
|
|
'id' => 'app_icon'));
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form guide.
|
2010-01-07 09:55:57 +00:00
|
|
|
$this->out->element('p', 'form_guide', _('Icon for this application'));
|
|
|
|
$this->out->element('input', array('name' => 'MAX_FILE_SIZE',
|
2010-01-13 07:33:51 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'id' => 'MAX_FILE_SIZE',
|
|
|
|
'value' => ImageFile::maxFileSizeInt()));
|
2010-01-07 09:55:57 +00:00
|
|
|
$this->out->elementEnd('li');
|
|
|
|
|
2010-01-12 02:50:54 +00:00
|
|
|
$this->out->elementStart('li');
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->hidden('application_id', $id);
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field label for application name.
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->input('name', _('Name'),
|
|
|
|
($this->out->arg('name')) ? $this->out->arg('name') : $name);
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('li');
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementStart('li');
|
2009-11-17 00:58:49 +00:00
|
|
|
|
|
|
|
$maxDesc = Oauth_application::maxDesc();
|
|
|
|
if ($maxDesc > 0) {
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field instructions.
|
2010-01-14 22:38:29 +00:00
|
|
|
$descInstr = sprintf(_('Describe your application in %d characters'),
|
2010-01-13 07:33:51 +00:00
|
|
|
$maxDesc);
|
2009-11-17 00:58:49 +00:00
|
|
|
} else {
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field instructions.
|
2009-11-17 00:58:49 +00:00
|
|
|
$descInstr = _('Describe your application');
|
|
|
|
}
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field label.
|
2009-11-17 00:58:49 +00:00
|
|
|
$this->out->textarea('description', _('Description'),
|
|
|
|
($this->out->arg('description')) ? $this->out->arg('description') : $description,
|
2010-01-13 07:33:51 +00:00
|
|
|
$descInstr);
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('li');
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementStart('li');
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field instructions.
|
|
|
|
$instruction = _('URL of the homepage of this application');
|
|
|
|
// TRANS: Form input field label.
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->input('source_url', _('Source URL'),
|
|
|
|
($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
|
2010-04-10 21:50:15 +01:00
|
|
|
$instruction);
|
2009-11-17 00:58:49 +00:00
|
|
|
$this->out->elementEnd('li');
|
2009-11-14 03:02:18 +00:00
|
|
|
|
|
|
|
$this->out->elementStart('li');
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field instructions.
|
|
|
|
$instruction = _('Organization responsible for this application');
|
|
|
|
// TRANS: Form input field label.
|
2009-11-17 00:58:49 +00:00
|
|
|
$this->out->input('organization', _('Organization'),
|
|
|
|
($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
|
2010-04-10 21:50:15 +01:00
|
|
|
$instruction);
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('li');
|
|
|
|
|
|
|
|
$this->out->elementStart('li');
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field instructions.
|
|
|
|
$instruction = _('URL for the homepage of the organization');
|
|
|
|
// TRANS: Form input field label.
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->input('homepage', _('Homepage'),
|
|
|
|
($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
|
2010-04-10 21:50:15 +01:00
|
|
|
$instruction);
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('li');
|
|
|
|
|
|
|
|
$this->out->elementStart('li');
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form input field instructions.
|
|
|
|
$instruction = _('URL to redirect to after authentication');
|
|
|
|
// TRANS: Form input field label.
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->input('callback_url', ('Callback URL'),
|
|
|
|
($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
|
2010-04-10 21:50:15 +01:00
|
|
|
$instruction);
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('li');
|
|
|
|
|
2010-01-12 02:50:54 +00:00
|
|
|
$this->out->elementStart('li', array('id' => 'application_types'));
|
2009-11-17 00:58:49 +00:00
|
|
|
|
|
|
|
$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
|
2010-01-07 09:55:57 +00:00
|
|
|
|| empty($this->application->type)) {
|
2009-11-17 00:58:49 +00:00
|
|
|
$attrs['checked'] = 'checked';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->out->element('input', $attrs);
|
|
|
|
|
|
|
|
$this->out->element('label', array('for' => 'app_type-browser',
|
2010-01-13 07:33:51 +00:00
|
|
|
'class' => 'radio'),
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Radio button label for application type
|
2010-01-13 07:33:51 +00:00
|
|
|
_('Browser'));
|
2009-11-17 00:58:49 +00:00
|
|
|
|
|
|
|
$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',
|
2010-01-13 07:33:51 +00:00
|
|
|
'class' => 'radio'),
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Radio button label for application type
|
2010-01-13 07:33:51 +00:00
|
|
|
_('Desktop'));
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form guide.
|
2009-11-17 00:58:49 +00:00
|
|
|
$this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('li');
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2010-01-12 02:50:54 +00:00
|
|
|
$this->out->elementStart('li', array('id' => 'default_access_types'));
|
2009-11-17 00:58:49 +00:00
|
|
|
|
|
|
|
$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',
|
2010-01-13 07:33:51 +00:00
|
|
|
'class' => 'radio'),
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Radio button label for access type.
|
2010-01-13 07:33:51 +00:00
|
|
|
_('Read-only'));
|
2009-11-17 00:58:49 +00:00
|
|
|
|
|
|
|
$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
|
2010-01-13 07:33:51 +00:00
|
|
|
) {
|
2009-11-17 00:58:49 +00:00
|
|
|
$attrs['checked'] = 'checked';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->out->element('input', $attrs);
|
|
|
|
|
|
|
|
$this->out->element('label', array('for' => 'default_access_type-rw',
|
2010-01-13 07:33:51 +00:00
|
|
|
'class' => 'radio'),
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Radio button label for access type.
|
2010-01-13 07:33:51 +00:00
|
|
|
_('Read-write'));
|
2010-04-10 21:50:15 +01:00
|
|
|
// TRANS: Form guide.
|
2009-11-17 00:58:49 +00:00
|
|
|
$this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
|
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('li');
|
2009-11-17 00:58:49 +00:00
|
|
|
|
2009-11-14 03:02:18 +00:00
|
|
|
$this->out->elementEnd('ul');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action elements
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function formActions()
|
|
|
|
{
|
2010-09-12 23:57:35 +01:00
|
|
|
// TRANS: Button label in the "Edit application" form.
|
2010-04-10 21:50:15 +01:00
|
|
|
$this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
|
2010-09-12 23:57:35 +01:00
|
|
|
// TRANS: Submit button title.
|
2010-01-13 07:33:51 +00:00
|
|
|
'cancel', _('Cancel'));
|
2010-09-12 23:57:35 +01:00
|
|
|
// TRANS: Button label in the "Edit application" form.
|
2010-04-10 21:50:15 +01:00
|
|
|
$this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
|
2010-09-12 23:57:35 +01:00
|
|
|
// TRANS: Submit button title.
|
2010-01-13 07:33:51 +00:00
|
|
|
'save', _('Save'));
|
2009-11-14 03:02:18 +00:00
|
|
|
}
|
|
|
|
}
|