diff options
author | Zach Copley <zach@status.net> | 2009-11-19 15:17:59 -0800 |
---|---|---|
committer | Zach Copley <zach@status.net> | 2009-11-19 15:17:59 -0800 |
commit | 69ac99ff949ab0118ff25a62471980ad0ec7a52b (patch) | |
tree | d1bbf0360dff14e876835f4d6800111931a626e2 | |
parent | 951e1c62044d620cf9aceb04b9f7955ca24d8d6d (diff) | |
parent | 288d875b79684f84d0fb1da5291de94ddf099a74 (diff) |
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
-rw-r--r-- | actions/useradminpanel.php | 155 | ||||
-rw-r--r-- | lib/adminpanelaction.php | 3 | ||||
-rw-r--r-- | lib/router.php | 2 |
3 files changed, 125 insertions, 35 deletions
diff --git a/actions/useradminpanel.php b/actions/useradminpanel.php index de475a27b..e65769212 100644 --- a/actions/useradminpanel.php +++ b/actions/useradminpanel.php @@ -90,13 +90,28 @@ class UseradminpanelAction extends AdminPanelAction function saveSettings() { - static $settings = array('theme'); - static $booleans = array('closed', 'inviteonly', 'private'); + static $settings = array( + 'profile' => array('biolimit'), + 'newuser' => array('welcome', 'default') + ); + + static $booleans = array( + 'sessions' => array('handle', 'debug'), + 'invite' => array('enabled') + ); $values = array(); - foreach ($settings as $setting) { - $values[$setting] = $this->trimmed($setting); + foreach ($settings as $section => $parts) { + 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 @@ -109,8 +124,16 @@ class UseradminpanelAction extends AdminPanelAction $config->query('BEGIN'); - foreach ($settings as $setting) { - Config::save('site', $setting, $values[$setting]); + foreach ($settings as $section => $parts) { + 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'); @@ -120,10 +143,35 @@ class UseradminpanelAction extends AdminPanelAction 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 @@ -144,7 +192,7 @@ class UserAdminPanelForm extends Form function formClass() { - return 'form_user_admin_panel'; + return 'form_settings'; } /** @@ -166,53 +214,92 @@ class UserAdminPanelForm extends Form 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->checkbox('closed', _('Closed'), - (bool) $this->value('closed'), - _('Is registration on this site prohibited?')); + $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->checkbox('inviteonly', _('Invite-only'), - (bool) $this->value('inviteonly'), - _('Is registration on this site only open to invited users?')); + $this->out->elementStart('fieldset', array('id' => 'settings_user-invitations')); + $this->out->element('legend', null, _('Invitations')); + $this->out->elementStart('ul', 'form_data'); + + $this->li(); + $this->out->checkbox('invite-enabled', _('Invitations enabled'), + (bool) $this->value('enabled', 'invite'), + _('Whether to allow users to invite new users.')); $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->out->checkbox('sessions-handle', _('Handle sessions'), + (bool) $this->value('handle', 'sessions'), + _('Whether to handle sessions ourselves.')); + $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 - * 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 $title Title to use for the input * @param string $instructions Instructions for this field + * @param string $section config section, default = 'site' * * @return void */ - function input($setting, $title, $instructions) - { - $this->out->input($setting, $title, $this->value($setting), $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) + function input($setting, $title, $instructions, $section='site') { - $value = $this->out->trimmed($setting); - if (empty($value)) { - $value = common_config($cat, $setting); - } - return $value; + $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions); } /** diff --git a/lib/adminpanelaction.php b/lib/adminpanelaction.php index 89a129db1..7997eb2b1 100644 --- a/lib/adminpanelaction.php +++ b/lib/adminpanelaction.php @@ -302,6 +302,9 @@ class AdminPanelNav extends Widget $this->out->menuItem(common_local_url('designadminpanel'), _('Design'), _('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'), _('Paths configuration'), $action_name == 'pathsadminpanel', 'nav_design_admin_panel'); diff --git a/lib/router.php b/lib/router.php index afe36f712..b22185126 100644 --- a/lib/router.php +++ b/lib/router.php @@ -590,9 +590,9 @@ class Router $m->connect('admin/site', array('action' => 'siteadminpanel')); $m->connect('admin/design', array('action' => 'designadminpanel')); + $m->connect('admin/user', array('action' => 'useradminpanel')); $m->connect('admin/paths', array('action' => 'pathsadminpanel')); - $m->connect('getfile/:filename', array('action' => 'getfile'), array('filename' => '[A-Za-z0-9._-]+')); |