diff --git a/phpBB/config/profilefields.yml b/phpBB/config/profilefields.yml index 4fac8bed9b..37df3d9019 100644 --- a/phpBB/config/profilefields.yml +++ b/phpBB/config/profilefields.yml @@ -8,17 +8,47 @@ services: - @template - @user - profilefields.admin: - class: \phpbb\profilefields\admin + profilefields.type.bool: + class: \phpbb\profilefields\type\type_bool arguments: - - @auth - - @config - - @dbal.conn - - @request - - @template + - @profilefields - @user + tags: + - { name: profilefield.type } - #migrator.tool.permission1: - # class: \phpbb\profilefields\profilefields - # tags: - # - { name: ffoobar.tool } + profilefields.type.date: + class: \phpbb\profilefields\type\type_date + arguments: + - @profilefields + - @user + tags: + - { name: profilefield.type } + + profilefields.type.dropdown: + class: \phpbb\profilefields\type\type_dropdown + arguments: + - @profilefields + - @user + tags: + - { name: profilefield.type } + + profilefields.type.int: + class: \phpbb\profilefields\type\type_int + arguments: + - @user + tags: + - { name: profilefield.type } + + profilefields.type.string: + class: \phpbb\profilefields\type\type_string + arguments: + - @user + tags: + - { name: profilefield.type } + + profilefields.type.text: + class: \phpbb\profilefields\type\type_text + arguments: + - @user + tags: + - { name: profilefield.type } diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 3c2e6448ce..44c2e0f11e 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -49,17 +49,7 @@ class acp_profile trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } - // Define some default values for each field type - $default_values = array( - FIELD_STRING => array('field_length' => 10, 'field_minlen' => 0, 'field_maxlen' => 20, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''), - FIELD_TEXT => array('field_length' => '5|80', 'field_minlen' => 0, 'field_maxlen' => 1000, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''), - FIELD_INT => array('field_length' => 5, 'field_minlen' => 0, 'field_maxlen' => 100, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0), - FIELD_DATE => array('field_length' => 10, 'field_minlen' => 10, 'field_maxlen' => 10, 'field_validation' => '', 'field_novalue' => ' 0- 0- 0', 'field_default_value' => ' 0- 0- 0'), - FIELD_BOOL => array('field_length' => 1, 'field_minlen' => 0, 'field_maxlen' => 0, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0), - FIELD_DROPDOWN => array('field_length' => 0, 'field_minlen' => 0, 'field_maxlen' => 5, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0), - ); - - $cp = $phpbb_container->get('profilefields.admin'); + $cp = $phpbb_container->get('profilefields'); // Build Language array // Based on this, we decide which elements need to be edited later and which language items are missing @@ -93,10 +83,10 @@ class acp_profile // Have some fields been defined? if (isset($this->lang_defs['entry'])) { - foreach ($this->lang_defs['entry'] as $field_id => $field_ary) + foreach ($this->lang_defs['entry'] as $field_ident => $field_ary) { // Fill an array with the languages that are missing for each field - $this->lang_defs['diff'][$field_id] = array_diff(array_values($this->lang_defs['iso']), $field_ary); + $this->lang_defs['diff'][$field_ident] = array_diff(array_values($this->lang_defs['iso']), $field_ary); } } @@ -381,7 +371,8 @@ class acp_profile trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } - $field_row = array_merge($default_values[$field_type], array( + $profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]); + $field_row = array_merge($profile_field->get_default_values(), array( 'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))), 'field_required' => 0, 'field_show_novalue'=> 0, @@ -848,8 +839,8 @@ class acp_profile ); // Build options based on profile type - $function = 'get_' . $cp->profile_types[$field_type] . '_options'; - $options = $cp->$function($this->lang_defs); + $profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]); + $options = $profile_field->get_options($this->lang_defs, $cp->vars); foreach ($options as $num => $option_ary) { diff --git a/phpBB/phpbb/profilefields/admin.php b/phpBB/phpbb/profilefields/admin.php deleted file mode 100644 index 1cca496265..0000000000 --- a/phpBB/phpbb/profilefields/admin.php +++ /dev/null @@ -1,190 +0,0 @@ -auth = $auth; - $this->config = $config; - $this->db = $db; - $this->request = $request; - $this->template = $template; - $this->user = $user; - } - - /** - * Return possible validation options - */ - function validate_options() - { - $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); - - $validate_options = ''; - foreach ($validate_ary as $lang => $value) - { - $selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : ''; - $validate_options .= ''; - } - - return $validate_options; - } - - /** - * Get string options for second step in ACP - */ - function get_string_options($lang_defs) - { - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') - ); - - return $options; - } - - /** - * Get text options for second step in ACP - */ - function get_text_options($lang_defs) - { - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $user->lang['ROWS'] . '
' . $user->lang['COLUMNS'] . ' '), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') - ); - - return $options; - } - - /** - * Get int options for second step in ACP - */ - function get_int_options($lang_defs) - { - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '') - ); - - return $options; - } - - /** - * Get bool options for second step in ACP - */ - function get_bool_options($lang_defs) - { - $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; - - $profile_row = array( - 'var_name' => 'field_default_value', - 'field_id' => 1, - 'lang_name' => $this->vars['lang_name'], - 'lang_explain' => $this->vars['lang_explain'], - 'lang_id' => $default_lang_id, - 'field_default_value' => $this->vars['field_default_value'], - 'field_ident' => 'field_default_value', - 'field_type' => FIELD_BOOL, - 'field_length' => $this->vars['field_length'], - 'lang_options' => $this->vars['lang_options'] - ); - - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)) - ); - - return $options; - } - - /** - * Get dropdown options for second step in ACP - */ - function get_dropdown_options($lang_defs) - { - $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; - - $profile_row[0] = array( - 'var_name' => 'field_default_value', - 'field_id' => 1, - 'lang_name' => $this->vars['lang_name'], - 'lang_explain' => $this->vars['lang_explain'], - 'lang_id' => $default_lang_id, - 'field_default_value' => $this->vars['field_default_value'], - 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DROPDOWN, - 'lang_options' => $this->vars['lang_options'] - ); - - $profile_row[1] = $profile_row[0]; - $profile_row[1]['var_name'] = 'field_novalue'; - $profile_row[1]['field_ident'] = 'field_novalue'; - $profile_row[1]['field_default_value'] = $this->vars['field_novalue']; - - $options = array( - 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])), - 1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1])) - ); - - return $options; - } - - /** - * Get date options for second step in ACP - */ - function get_date_options($lang_defs) - { - $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; - - $profile_row = array( - 'var_name' => 'field_default_value', - 'lang_name' => $this->vars['lang_name'], - 'lang_explain' => $this->vars['lang_explain'], - 'lang_id' => $default_lang_id, - 'field_default_value' => $this->vars['field_default_value'], - 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DATE, - 'field_length' => $this->vars['field_length'] - ); - - $always_now = request_var('always_now', -1); - if ($always_now == -1) - { - $s_checked = ($this->vars['field_default_value'] == 'now') ? true : false; - } - else - { - $s_checked = ($always_now) ? true : false; - } - - $options = array( - 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), - 1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => ''), - ); - - return $options; - } -} diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php new file mode 100644 index 0000000000..b3dafa30d4 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -0,0 +1,63 @@ +profilefields = $profilefields; + $this->user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $profile_row = array( + 'var_name' => 'field_default_value', + 'field_id' => 1, + 'lang_name' => $field_data['lang_name'], + 'lang_explain' => $field_data['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $field_data['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_BOOL, + 'field_length' => $field_data['field_length'], + 'lang_options' => $field_data['lang_options'] + ); + + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)) + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 1, + 'field_minlen' => 0, + 'field_maxlen' => 0, + 'field_validation' => '', + 'field_novalue' => 0, + 'field_default_value' => 0, + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php new file mode 100644 index 0000000000..9639b45770 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -0,0 +1,71 @@ +profilefields = $profilefields; + $this->user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $profile_row = array( + 'var_name' => 'field_default_value', + 'lang_name' => $field_data['lang_name'], + 'lang_explain' => $field_data['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $field_data['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_DATE, + 'field_length' => $field_data['field_length'] + ); + + $always_now = request_var('always_now', -1); + if ($always_now == -1) + { + $s_checked = ($field_data['field_default_value'] == 'now') ? true : false; + } + else + { + $s_checked = ($always_now) ? true : false; + } + + $options = array( + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)), + 1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => ''), + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 10, + 'field_minlen' => 10, + 'field_maxlen' => 10, + 'field_validation' => '', + 'field_novalue' => ' 0- 0- 0', + 'field_default_value' => ' 0- 0- 0', + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php new file mode 100644 index 0000000000..8a101f1fc1 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -0,0 +1,67 @@ +profilefields = $profilefields; + $this->user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $profile_row[0] = array( + 'var_name' => 'field_default_value', + 'field_id' => 1, + 'lang_name' => $field_data['lang_name'], + 'lang_explain' => $field_data['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $field_data['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_DROPDOWN, + 'lang_options' => $field_data['lang_options'] + ); + + $profile_row[1] = $profile_row[0]; + $profile_row[1]['var_name'] = 'field_novalue'; + $profile_row[1]['field_ident'] = 'field_novalue'; + $profile_row[1]['field_default_value'] = $field_data['field_novalue']; + + $options = array( + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[0])), + 1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[1])) + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 0, + 'field_minlen' => 0, + 'field_maxlen' => 5, + 'field_validation' => '', + 'field_novalue' => 0, + 'field_default_value' => 0, + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php new file mode 100644 index 0000000000..7cc74b6e44 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -0,0 +1,51 @@ +user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '') + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 5, + 'field_minlen' => 0, + 'field_maxlen' => 100, + 'field_validation' => '', + 'field_novalue' => 0, + 'field_default_value' => 0, + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php new file mode 100644 index 0000000000..8b011aa48e --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -0,0 +1,39 @@ +user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 10, + 'field_minlen' => 0, + 'field_maxlen' => 20, + 'field_validation' => '.*', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php new file mode 100644 index 0000000000..dc2cd2f157 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -0,0 +1,30 @@ + '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); + + $validate_options = ''; + foreach ($validate_ary as $lang => $value) + { + $selected = ($field_data['field_validation'] == $value) ? ' selected="selected"' : ''; + $validate_options .= ''; + } + + return $validate_options; + } +} diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php new file mode 100644 index 0000000000..4b58ef0486 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -0,0 +1,51 @@ +user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $this->user->lang['ROWS'] . '
' . $this->user->lang['COLUMNS'] . ' '), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => '5|80', + 'field_minlen' => 0, + 'field_maxlen' => 1000, + 'field_validation' => '.*', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } +}