From a2f2629e2a5038aca372cc3e55c408a99b6ca6fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Feb 2014 23:02:54 +0100 Subject: [PATCH] [ticket/12187] Add URL type for profile fields PHPBB3-12187 --- phpBB/adm/style/profilefields/url.html | 3 + phpBB/config/profilefields.yml | 9 ++ phpBB/language/en/acp/profile.php | 1 + phpBB/language/en/ucp.php | 1 + phpBB/phpbb/profilefields/type/type_int.php | 2 +- .../phpbb/profilefields/type/type_string.php | 2 +- phpBB/phpbb/profilefields/type/type_url.php | 83 +++++++++++++++++++ .../prosilver/template/profilefields/url.html | 3 + .../template/profilefields/url.html | 3 + 9 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 phpBB/adm/style/profilefields/url.html create mode 100644 phpBB/phpbb/profilefields/type/type_url.php create mode 100644 phpBB/styles/prosilver/template/profilefields/url.html create mode 100644 phpBB/styles/subsilver2/template/profilefields/url.html diff --git a/phpBB/adm/style/profilefields/url.html b/phpBB/adm/style/profilefields/url.html new file mode 100644 index 0000000000..8dd3a90de1 --- /dev/null +++ b/phpBB/adm/style/profilefields/url.html @@ -0,0 +1,3 @@ + + + diff --git a/phpBB/config/profilefields.yml b/phpBB/config/profilefields.yml index 5a861a4b56..d12a1f8a37 100644 --- a/phpBB/config/profilefields.yml +++ b/phpBB/config/profilefields.yml @@ -80,3 +80,12 @@ services: - @user tags: - { name: profilefield.type } + + profilefields.type.url: + class: phpbb\profilefields\type\type_url + arguments: + - @request + - @template + - @user + tags: + - { name: profilefield.type } diff --git a/phpBB/language/en/acp/profile.php b/phpBB/language/en/acp/profile.php index 0ea95c35ba..93162daa45 100644 --- a/phpBB/language/en/acp/profile.php +++ b/phpBB/language/en/acp/profile.php @@ -100,6 +100,7 @@ $lang = array_merge($lang, array( 'FIELD_TEXT' => 'Textarea', 'FIELD_TYPE' => 'Field type', 'FIELD_TYPE_EXPLAIN' => 'You are not able to change the field type later.', + 'FIELD_URL' => 'URL (Link)', 'FIELD_VALIDATION' => 'Field validation', 'FIRST_OPTION' => 'First option', diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 1520af9ef8..6970319397 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -209,6 +209,7 @@ $lang = array_merge($lang, array( 'FIELD_INVALID_CHARS_ALPHA_ONLY' => 'The field “%s” has invalid characters, only alphanumeric characters are allowed.', 'FIELD_INVALID_CHARS_SPACERS_ONLY' => 'The field “%s” has invalid characters, only alphanumeric, space or -+_[] characters are allowed.', 'FIELD_INVALID_DATE' => 'The field “%s” has an invalid date.', + 'FIELD_INVALID_URL' => 'The field “%s” has an invalid url.', 'FIELD_INVALID_VALUE' => 'The field “%s” has an invalid value.', 'FOE_MESSAGE' => 'Message from foe', diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 267f522d5d..c98c863e13 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -61,7 +61,7 @@ class type_int extends type_base 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' => ''), + 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => ''), ); return $options; diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 9d241c49ef..9dada592eb 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -109,7 +109,7 @@ class type_string extends type_string_common $default_value = $profile_row['lang_default_value']; $profile_row['field_value'] = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value, true) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]); - $this->template->assign_block_vars('string', array_change_key_case($profile_row, CASE_UPPER)); + $this->template->assign_block_vars($this->get_name_short(), array_change_key_case($profile_row, CASE_UPPER)); } /** diff --git a/phpBB/phpbb/profilefields/type/type_url.php b/phpBB/phpbb/profilefields/type/type_url.php new file mode 100644 index 0000000000..08f976cf4b --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_url.php @@ -0,0 +1,83 @@ + 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' => ''), + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_option_values() + { + return array( + 'field_length' => 40, + 'field_minlen' => 0, + 'field_maxlen' => 200, + 'field_validation' => '', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } + + /** + * {@inheritDoc} + */ + public function get_profile_value($field_value, $field_data) + { + if (!$field_value && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + + /** + * {@inheritDoc} + */ + public function validate_profile_field(&$field_value, $field_data) + { + $field_value = trim($field_value); + + if ($field_value === '' && !$field_data['field_required']) + { + return false; + } + + if (!preg_match('#^' . get_preg_expression('url') . '$#i', $field_value)) + { + return $this->user->lang('FIELD_INVALID_URL', $this->get_field_name($field_data['lang_name'])); + } + + return false; + } +} diff --git a/phpBB/styles/prosilver/template/profilefields/url.html b/phpBB/styles/prosilver/template/profilefields/url.html new file mode 100644 index 0000000000..8dd3a90de1 --- /dev/null +++ b/phpBB/styles/prosilver/template/profilefields/url.html @@ -0,0 +1,3 @@ + + + diff --git a/phpBB/styles/subsilver2/template/profilefields/url.html b/phpBB/styles/subsilver2/template/profilefields/url.html new file mode 100644 index 0000000000..42805aa98d --- /dev/null +++ b/phpBB/styles/subsilver2/template/profilefields/url.html @@ -0,0 +1,3 @@ + + +