* @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see * the docs/CREDITS.txt file. * */ namespace phpbb\profilefields\type; class type_url extends type_string { /** * {@inheritDoc} */ public function get_name_short() { return 'url'; } /** * {@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' => ''), ); 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 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_http') . '$#iu', $field_value)) { return $this->user->lang('FIELD_INVALID_URL', $this->get_field_name($field_data['lang_name'])); } return false; } /** * {@inheritDoc} */ public function get_profile_value($field_value, $field_data) { if (!preg_match('#^' . get_preg_expression('url_http') . '$#iu', $field_value)) { return null; } return parent::get_profile_value($field_value, $field_data); } }