Merge branch 'admin-sections/4' into 0.9.x
* admin-sections/4: Added validation to fields in user admin panel Added a user admin panel
This commit is contained in:
commit
69ac99ff94
@ -90,13 +90,28 @@ class UseradminpanelAction extends AdminPanelAction
|
|||||||
|
|
||||||
function saveSettings()
|
function saveSettings()
|
||||||
{
|
{
|
||||||
static $settings = array('theme');
|
static $settings = array(
|
||||||
static $booleans = array('closed', 'inviteonly', 'private');
|
'profile' => array('biolimit'),
|
||||||
|
'newuser' => array('welcome', 'default')
|
||||||
|
);
|
||||||
|
|
||||||
|
static $booleans = array(
|
||||||
|
'sessions' => array('handle', 'debug'),
|
||||||
|
'invite' => array('enabled')
|
||||||
|
);
|
||||||
|
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
foreach ($settings as $setting) {
|
foreach ($settings as $section => $parts) {
|
||||||
$values[$setting] = $this->trimmed($setting);
|
foreach ($parts as $setting) {
|
||||||
|
$values[$section][$setting] = $this->trimmed("$section-$setting");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($booleans as $section => $parts) {
|
||||||
|
foreach ($parts as $setting) {
|
||||||
|
$values[$section][$setting] = ($this->boolean("$section-$setting")) ? 1 : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This throws an exception on validation errors
|
// This throws an exception on validation errors
|
||||||
@ -109,8 +124,16 @@ class UseradminpanelAction extends AdminPanelAction
|
|||||||
|
|
||||||
$config->query('BEGIN');
|
$config->query('BEGIN');
|
||||||
|
|
||||||
foreach ($settings as $setting) {
|
foreach ($settings as $section => $parts) {
|
||||||
Config::save('site', $setting, $values[$setting]);
|
foreach ($parts as $setting) {
|
||||||
|
Config::save($section, $setting, $values[$section][$setting]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($booleans as $section => $parts) {
|
||||||
|
foreach ($parts as $setting) {
|
||||||
|
Config::save($section, $setting, $values[$section][$setting]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->query('COMMIT');
|
$config->query('COMMIT');
|
||||||
@ -120,10 +143,35 @@ class UseradminpanelAction extends AdminPanelAction
|
|||||||
|
|
||||||
function validate(&$values)
|
function validate(&$values)
|
||||||
{
|
{
|
||||||
|
// Validate biolimit
|
||||||
|
|
||||||
|
if (!Validate::number($values['profile']['biolimit'])) {
|
||||||
|
$this->clientError(_("Invalid bio limit. Must be numeric."));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate welcome text
|
||||||
|
|
||||||
|
if (mb_strlen($values['newuser']['welcome']) > 255) {
|
||||||
|
$this->clientError(_("Invalid welcome text. Max length is 255 characters."));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate default subscription
|
||||||
|
|
||||||
|
if (!empty($values['newuser']['default'])) {
|
||||||
|
$defuser = User::staticGet('nickname', trim($values['newuser']['default']));
|
||||||
|
if (empty($defuser)) {
|
||||||
|
$this->clientError(
|
||||||
|
sprintf(
|
||||||
|
_('Invalid default subscripton: \'%1$s\' is not user.'),
|
||||||
|
$values['newuser']['default']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserAdminPanelForm extends Form
|
class UserAdminPanelForm extends AdminForm
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* ID of the form
|
* ID of the form
|
||||||
@ -144,7 +192,7 @@ class UserAdminPanelForm extends Form
|
|||||||
|
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_user_admin_panel';
|
return 'form_settings';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,53 +214,92 @@ class UserAdminPanelForm extends Form
|
|||||||
|
|
||||||
function formData()
|
function formData()
|
||||||
{
|
{
|
||||||
|
$this->out->elementStart('fieldset', array('id' => 'settings_user-profile'));
|
||||||
|
$this->out->element('legend', null, _('Profile'));
|
||||||
|
$this->out->elementStart('ul', 'form_data');
|
||||||
|
|
||||||
|
$this->li();
|
||||||
|
$this->input('biolimit', _('Bio Limit'),
|
||||||
|
_('Maximum length of a profile bio in characters.'),
|
||||||
|
'profile');
|
||||||
|
$this->unli();
|
||||||
|
|
||||||
|
$this->out->elementEnd('ul');
|
||||||
|
$this->out->elementEnd('fieldset');
|
||||||
|
|
||||||
|
$this->out->elementStart('fieldset', array('id' => 'settings_user-newusers'));
|
||||||
|
$this->out->element('legend', null, _('New users'));
|
||||||
|
$this->out->elementStart('ul', 'form_data');
|
||||||
|
|
||||||
|
$this->li();
|
||||||
|
$this->input('welcome', _('New user welcome'),
|
||||||
|
_('Welcome text for new users (Max 255 chars).'),
|
||||||
|
'newuser');
|
||||||
|
$this->unli();
|
||||||
|
|
||||||
|
$this->li();
|
||||||
|
$this->input('default', _('Default subscription'),
|
||||||
|
_('Automatically subscribe new users to this user.'),
|
||||||
|
'newuser');
|
||||||
|
$this->unli();
|
||||||
|
|
||||||
|
$this->out->elementEnd('ul');
|
||||||
|
|
||||||
|
$this->out->elementEnd('fieldset');
|
||||||
|
|
||||||
|
$this->out->elementStart('fieldset', array('id' => 'settings_user-invitations'));
|
||||||
|
$this->out->element('legend', null, _('Invitations'));
|
||||||
|
$this->out->elementStart('ul', 'form_data');
|
||||||
|
|
||||||
$this->li();
|
$this->li();
|
||||||
|
|
||||||
$this->out->checkbox('closed', _('Closed'),
|
$this->out->checkbox('invite-enabled', _('Invitations enabled'),
|
||||||
(bool) $this->value('closed'),
|
(bool) $this->value('enabled', 'invite'),
|
||||||
_('Is registration on this site prohibited?'));
|
_('Whether to allow users to invite new users.'));
|
||||||
|
|
||||||
$this->unli();
|
$this->unli();
|
||||||
|
|
||||||
|
$this->out->elementEnd('ul');
|
||||||
|
$this->out->elementEnd('fieldset');
|
||||||
|
|
||||||
|
$this->out->elementStart('fieldset', array('id' => 'settings_user_sessions'));
|
||||||
|
$this->out->element('legend', null, _('Sessions'));
|
||||||
|
|
||||||
|
$this->out->elementStart('ul');
|
||||||
|
|
||||||
$this->li();
|
$this->li();
|
||||||
|
$this->out->checkbox('sessions-handle', _('Handle sessions'),
|
||||||
$this->out->checkbox('inviteonly', _('Invite-only'),
|
(bool) $this->value('handle', 'sessions'),
|
||||||
(bool) $this->value('inviteonly'),
|
_('Whether to handle sessions ourselves.'));
|
||||||
_('Is registration on this site only open to invited users?'));
|
|
||||||
|
|
||||||
$this->unli();
|
$this->unli();
|
||||||
|
|
||||||
|
$this->li();
|
||||||
|
$this->out->checkbox('sessions-debug', _('Session debugging'),
|
||||||
|
(bool) $this->value('debug', 'sessions'),
|
||||||
|
_('Turn on debugging output for sessions.'));
|
||||||
|
$this->unli();
|
||||||
|
|
||||||
|
$this->out->elementEnd('ul');
|
||||||
|
|
||||||
|
$this->out->elementEnd('fieldset');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility to simplify some of the duplicated code around
|
* Utility to simplify some of the duplicated code around
|
||||||
* params and settings.
|
* params and settings. Overrided from base class to be
|
||||||
|
* more specific about input ids.
|
||||||
*
|
*
|
||||||
* @param string $setting Name of the setting
|
* @param string $setting Name of the setting
|
||||||
* @param string $title Title to use for the input
|
* @param string $title Title to use for the input
|
||||||
* @param string $instructions Instructions for this field
|
* @param string $instructions Instructions for this field
|
||||||
|
* @param string $section config section, default = 'site'
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function input($setting, $title, $instructions)
|
function input($setting, $title, $instructions, $section='site')
|
||||||
{
|
{
|
||||||
$this->out->input($setting, $title, $this->value($setting), $instructions);
|
$this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility to simplify getting the posted-or-stored setting value
|
|
||||||
*
|
|
||||||
* @param string $setting Name of the setting
|
|
||||||
*
|
|
||||||
* @return string param value if posted, or current config value
|
|
||||||
*/
|
|
||||||
|
|
||||||
function value($cat, $setting)
|
|
||||||
{
|
|
||||||
$value = $this->out->trimmed($setting);
|
|
||||||
if (empty($value)) {
|
|
||||||
$value = common_config($cat, $setting);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -302,6 +302,9 @@ class AdminPanelNav extends Widget
|
|||||||
$this->out->menuItem(common_local_url('designadminpanel'), _('Design'),
|
$this->out->menuItem(common_local_url('designadminpanel'), _('Design'),
|
||||||
_('Design configuration'), $action_name == 'designadminpanel', 'nav_design_admin_panel');
|
_('Design configuration'), $action_name == 'designadminpanel', 'nav_design_admin_panel');
|
||||||
|
|
||||||
|
$this->out->menuItem(common_local_url('useradminpanel'), _('User'),
|
||||||
|
_('Paths configuration'), $action_name == 'useradminpanel', 'nav_design_admin_panel');
|
||||||
|
|
||||||
$this->out->menuItem(common_local_url('pathsadminpanel'), _('Paths'),
|
$this->out->menuItem(common_local_url('pathsadminpanel'), _('Paths'),
|
||||||
_('Paths configuration'), $action_name == 'pathsadminpanel', 'nav_design_admin_panel');
|
_('Paths configuration'), $action_name == 'pathsadminpanel', 'nav_design_admin_panel');
|
||||||
|
|
||||||
|
@ -590,9 +590,9 @@ class Router
|
|||||||
|
|
||||||
$m->connect('admin/site', array('action' => 'siteadminpanel'));
|
$m->connect('admin/site', array('action' => 'siteadminpanel'));
|
||||||
$m->connect('admin/design', array('action' => 'designadminpanel'));
|
$m->connect('admin/design', array('action' => 'designadminpanel'));
|
||||||
|
$m->connect('admin/user', array('action' => 'useradminpanel'));
|
||||||
$m->connect('admin/paths', array('action' => 'pathsadminpanel'));
|
$m->connect('admin/paths', array('action' => 'pathsadminpanel'));
|
||||||
|
|
||||||
|
|
||||||
$m->connect('getfile/:filename',
|
$m->connect('getfile/:filename',
|
||||||
array('action' => 'getfile'),
|
array('action' => 'getfile'),
|
||||||
array('filename' => '[A-Za-z0-9._-]+'));
|
array('filename' => '[A-Za-z0-9._-]+'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user