diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-01-17 13:35:38 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-01-17 13:59:07 +0100 |
commit | 67f477fc8f184e5b2585bda914e2fbbabf4afcd8 (patch) | |
tree | e86502a4ac1722901748fe51e0735e5a9317c722 /phpBB | |
parent | ae38cfaa701458aaebbc0991512d8788db07f9cb (diff) | |
download | forums-67f477fc8f184e5b2585bda914e2fbbabf4afcd8.tar forums-67f477fc8f184e5b2585bda914e2fbbabf4afcd8.tar.gz forums-67f477fc8f184e5b2585bda914e2fbbabf4afcd8.tar.bz2 forums-67f477fc8f184e5b2585bda914e2fbbabf4afcd8.tar.xz forums-67f477fc8f184e5b2585bda914e2fbbabf4afcd8.zip |
[ticket/11201] Allow manipulating the intended variables with the type class
PHPBB3-11201
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/acp/acp_profile.php | 105 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_base.php | 18 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_bool.php | 44 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_date.php | 42 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_dropdown.php | 15 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_int.php | 17 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_interface.php | 12 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_text.php | 26 |
8 files changed, 180 insertions, 99 deletions
diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 39d1c70990..a1b3c46146 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -450,93 +450,9 @@ class acp_profile { $var = utf8_normalize_nfc(request_var($key, $field_row[$key], true)); - // Manipulate the intended variables a little bit if needed - if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen') - { - // Get the number of options if this key is 'field_maxlen' - $var = sizeof(explode("\n", utf8_normalize_nfc(request_var('lang_options', '', true)))); - } - else if ($field_type == FIELD_TEXT && $key == 'field_length') - { - if (isset($_REQUEST['rows'])) - { - $cp->vars['rows'] = request_var('rows', 0); - $cp->vars['columns'] = request_var('columns', 0); - $var = $cp->vars['rows'] . '|' . $cp->vars['columns']; - } - else - { - $row_col = explode('|', $var); - $cp->vars['rows'] = $row_col[0]; - $cp->vars['columns'] = $row_col[1]; - } - } - else if ($field_type == FIELD_DATE && $key == 'field_default_value') - { - $always_now = request_var('always_now', -1); - - if ($always_now == 1 || ($always_now === -1 && $var == 'now')) - { - $now = getdate(); - - $cp->vars['field_default_value_day'] = $now['mday']; - $cp->vars['field_default_value_month'] = $now['mon']; - $cp->vars['field_default_value_year'] = $now['year']; - $var = 'now'; - $request->overwrite('field_default_value', $var, \phpbb\request\request_interface::POST); - } - else - { - if (isset($_REQUEST['field_default_value_day'])) - { - $cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0); - $cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0); - $cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0); - $var = sprintf('%2d-%2d-%4d', $cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']); - $request->overwrite('field_default_value', $var, \phpbb\request\request_interface::POST); - } - else - { - list($cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']) = explode('-', $var); - } - } - } - else if ($field_type == FIELD_BOOL && $key == 'field_default_value') - { - // 'field_length' == 1 defines radio buttons. Possible values are 1 or 2 only. - // 'field_length' == 2 defines checkbox. Possible values are 0 or 1 only. - // If we switch the type on step 2, we have to adjust field value. - // 1 is a common value for the checkbox and radio buttons. - - // Adjust unchecked checkbox value. - // If we return or save settings from 2nd/3rd page - // and the checkbox is unchecked, set the value to 0. - if (isset($_REQUEST['step']) && !isset($_REQUEST[$key])) - { - $var = 0; - } - - // If we switch to the checkbox type but former radio buttons value was 2, - // which is not the case for the checkbox, set it to 0 (unchecked). - if ($cp->vars['field_length'] == 2 && $var == 2) - { - $var = 0; - } - // If we switch to the radio buttons but the former checkbox value was 0, - // which is not the case for the radio buttons, set it to 0. - else if ($cp->vars['field_length'] == 1 && $var == 0) - { - $var = 2; - } - } - else if ($field_type == FIELD_INT && $key == 'field_default_value') - { - // Permit an empty string - if ($action == 'create' && request_var('field_default_value', '') === '') - { - $var = ''; - } - } + $field_data = $cp->vars; + $var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 2); + $cp->vars = $field_data; $cp->vars[$key] = $var; } @@ -585,18 +501,10 @@ class acp_profile { $cp->vars[$key] = $$key; } - else if ($key == 'l_lang_options' && $field_type == FIELD_BOOL) - { - $cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => array('')), true)); - } - else if ($key == 'l_lang_options' && is_array($cp->vars[$key])) - { - foreach ($cp->vars[$key] as $lang_id => $options) - { - $cp->vars[$key][$lang_id] = explode("\n", $options); - } - } + $field_data = $cp->vars; + $var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 3); + $cp->vars = $field_data; } // Check for general issues in every step @@ -812,7 +720,6 @@ class acp_profile ); // Build options based on profile type - $profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]); $options = $profile_field->get_options($this->lang_defs['iso'][$config['default_lang']], $cp->vars); foreach ($options as $num => $option_ary) diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 976411baee..cd03af57f7 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -57,4 +57,22 @@ abstract class type_base implements type_interface { return $error; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 3 && ($field_data[$key] || $action != 'edit') && $key == 'l_lang_options' && is_array($field_data[$key])) + { + foreach ($field_data[$key] as $lang_id => $options) + { + $field_data[$key][$lang_id] = explode("\n", $options); + } + + return $current_value; + } + + return $current_value; + } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 24319c2bfe..acf20e93e0 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -252,4 +252,48 @@ class type_bool extends type_base return $error; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_default_value') + { + // 'field_length' == 1 defines radio buttons. Possible values are 1 or 2 only. + // 'field_length' == 2 defines checkbox. Possible values are 0 or 1 only. + // If we switch the type on step 2, we have to adjust field value. + // 1 is a common value for the checkbox and radio buttons. + + // Adjust unchecked checkbox value. + // If we return or save settings from 2nd/3rd page + // and the checkbox is unchecked, set the value to 0. + if ($this->request->is_set('step') && !$this->request->is_set($key)) + { + return 0; + } + + // If we switch to the checkbox type but former radio buttons value was 2, + // which is not the case for the checkbox, set it to 0 (unchecked). + if ($field_data['field_length'] == 2 && $current_value == 2) + { + return 0; + } + // If we switch to the radio buttons but the former checkbox value was 0, + // which is not the case for the radio buttons, set it to 0. + else if ($field_data['field_length'] == 1 && $current_value == 0) + { + return 2; + } + } + + if ($step == 3 && ($field_data[$key] || $action != 'edit') && $key == 'l_lang_options') + { + $field_data[$key] = $this->request->variable($key, array(0 => array('')), true); + + return $current_value; + } + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index a2c9111351..099d1dbb50 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -258,4 +258,46 @@ class type_date extends type_base return $options; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_default_value') + { + $always_now = $this->request->variable('always_now', -1); + + if ($always_now == 1 || ($always_now === -1 && $current_value == 'now')) + { + $now = getdate(); + + $field_data['field_default_value_day'] = $now['mday']; + $field_data['field_default_value_month'] = $now['mon']; + $field_data['field_default_value_year'] = $now['year']; + $current_value = 'now'; + $this->request->overwrite('field_default_value', $current_value, \phpbb\request\request_interface::POST); + } + else + { + if ($this->request->is_set('field_default_value_day')) + { + $field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0); + $field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0); + $field_data['field_default_value_year'] = $this->request->variable('field_default_value_year', 0); + $current_value = sprintf('%2d-%2d-%4d', $field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']); + $this->request->overwrite('field_default_value', $current_value, \phpbb\request\request_interface::POST); + } + else + { + list($field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']) = explode('-', $current_value); + } + } + + return $current_value; + } + + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index a113b1d5ef..0bf36fcbfd 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -224,4 +224,19 @@ class type_dropdown extends type_base return $error; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_maxlen') + { + // Get the number of options if this key is 'field_maxlen' + return sizeof(explode("\n", $this->request->variable('lang_options', '', true))); + } + + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 2cd9d3b2c4..e22b45e7a4 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -183,4 +183,21 @@ class type_int extends type_base return $options; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_default_value') + { + // Permit an empty string + if ($action == 'create' && $this->request->variable('field_default_value', '') === '') + { + return ''; + } + } + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index ad67536543..7cbdd30ddf 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -131,4 +131,16 @@ interface type_interface * @return array Array with error messages */ public function validate_options_on_submit($error, $field_data); + + /** + * Allows manipulating the intended variables if needed + * + * @param string $key Name of the option + * @param string $action Currently performed action (create|edit) + * @param mixed $current_value Currently value of the option + * @param array $field_data Array with data for this field + * @param int $step Step on which the option is excluded + * @return mixed Final value of the option + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step); } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 309ed88818..4437334d2b 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -114,4 +114,30 @@ class type_text extends type_string_common return $options; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_length') + { + if ($this->request->is_set('rows')) + { + $field_data['rows'] = $this->request->variable('rows', 0); + $field_data['columns'] = $this->request->variable('columns', 0); + $current_value = $field_data['rows'] . '|' . $field_data['columns']; + } + else + { + $row_col = explode('|', $current_value); + $field_data['rows'] = $row_col[0]; + $field_data['columns'] = $row_col[1]; + } + + return $current_value; + } + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } |