mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/12187] Add URL type for profile fields
PHPBB3-12187
This commit is contained in:
@@ -61,7 +61,7 @@ class type_int extends type_base
|
||||
0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_length" size="5" value="' . $field_data['field_length'] . '" />'),
|
||||
1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_minlen" size="5" value="' . $field_data['field_minlen'] . '" />'),
|
||||
2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_maxlen" size="5" value="' . $field_data['field_maxlen'] . '" />'),
|
||||
3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $field_data['field_default_value'] . '" />'),
|
||||
3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="number" name="field_default_value" value="' . $field_data['field_default_value'] . '" />'),
|
||||
);
|
||||
|
||||
return $options;
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
83
phpBB/phpbb/profilefields/type/type_url.php
Normal file
83
phpBB/phpbb/profilefields/type/type_url.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
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' => '<input type="number" min="0" name="field_length" size="5" value="' . $field_data['field_length'] . '" />'),
|
||||
1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" name="field_minlen" size="5" value="' . $field_data['field_minlen'] . '" />'),
|
||||
2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" name="field_maxlen" size="5" value="' . $field_data['field_maxlen'] . '" />'),
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user