aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/profilefields
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/profilefields')
-rw-r--r--phpBB/phpbb/profilefields/manager.php176
-rw-r--r--phpBB/phpbb/profilefields/type/type_base.php8
-rw-r--r--phpBB/phpbb/profilefields/type/type_date.php1
-rw-r--r--phpBB/phpbb/profilefields/type/type_int.php4
-rw-r--r--phpBB/phpbb/profilefields/type/type_interface.php11
-rw-r--r--phpBB/phpbb/profilefields/type/type_string.php2
-rw-r--r--phpBB/phpbb/profilefields/type/type_string_common.php40
-rw-r--r--phpBB/phpbb/profilefields/type/type_url.php70
8 files changed, 221 insertions, 91 deletions
diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php
index ac2542a6d4..a4626bc5de 100644
--- a/phpBB/phpbb/profilefields/manager.php
+++ b/phpBB/phpbb/profilefields/manager.php
@@ -278,106 +278,132 @@ class manager
}
/**
- * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
- * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template
+ * Grab the user specific profile fields data
+ *
+ * @param int|array $user_ids Single user id or an array of ids
+ * @return array Users profile fields data
*/
- public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
+ public function grab_profile_fields_data($user_ids = 0)
{
- if ($mode == 'grab')
+ if (!is_array($user_ids))
{
- if (!is_array($user_id))
- {
- $user_id = array($user_id);
- }
+ $user_ids = array($user_ids);
+ }
- if (!sizeof($this->profile_cache))
- {
- $this->build_cache();
- }
+ if (!sizeof($this->profile_cache))
+ {
+ $this->build_cache();
+ }
- if (!sizeof($user_id))
- {
- return array();
- }
+ if (!sizeof($user_ids))
+ {
+ return array();
+ }
- $sql = 'SELECT *
- FROM ' . $this->fields_data_table . '
- WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id));
- $result = $this->db->sql_query($sql);
+ $sql = 'SELECT *
+ FROM ' . $this->fields_data_table . '
+ WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_ids));
+ $result = $this->db->sql_query($sql);
- $field_data = array();
- while ($row = $this->db->sql_fetchrow($result))
- {
- $field_data[$row['user_id']] = $row;
- }
- $this->db->sql_freeresult($result);
+ $field_data = array();
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $field_data[$row['user_id']] = $row;
+ }
+ $this->db->sql_freeresult($result);
- $user_fields = array();
+ $user_fields = array();
- $user_ids = $user_id;
+ // Go through the fields in correct order
+ foreach (array_keys($this->profile_cache) as $used_ident)
+ {
+ foreach ($field_data as $user_id => $row)
+ {
+ $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
+ $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
+ }
- // Go through the fields in correct order
- foreach (array_keys($this->profile_cache) as $used_ident)
+ foreach ($user_ids as $user_id)
{
- foreach ($field_data as $user_id => $row)
+ if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue'])
{
- $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
+ $user_fields[$user_id][$used_ident]['value'] = '';
$user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
}
-
- foreach ($user_ids as $user_id)
- {
- if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue'])
- {
- $user_fields[$user_id][$used_ident]['value'] = '';
- $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
- }
- }
}
-
- return $user_fields;
}
- else if ($mode == 'show')
+
+ return $user_fields;
+ }
+
+ /**
+ * Assign the user's profile fields data to the template
+ *
+ * @param array $profile_row Array with users profile field data
+ * @param bool $use_contact_fields Should we display contact fields as such?
+ * This requires special treatments (links should not be parsed in the values, and more)
+ * @return array
+ */
+ public function generate_profile_fields_template_data($profile_row, $use_contact_fields = true)
+ {
+ // $profile_row == $user_fields[$row['user_id']];
+ $tpl_fields = array();
+ $tpl_fields['row'] = $tpl_fields['blockrow'] = array();
+
+ foreach ($profile_row as $ident => $ident_ary)
{
- // $profile_row == $user_fields[$row['user_id']];
- $tpl_fields = array();
- $tpl_fields['row'] = $tpl_fields['blockrow'] = array();
+ $profile_field = $this->type_collection[$ident_ary['data']['field_type']];
+ $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
- foreach ($profile_row as $ident => $ident_ary)
+ if ($value === null)
{
- $profile_field = $this->type_collection[$ident_ary['data']['field_type']];
- $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
+ continue;
+ }
- if ($value === null)
+ $field_desc = $contact_url = '';
+ if ($use_contact_fields)
+ {
+ $value = $profile_field->get_profile_contact_value($ident_ary['value'], $ident_ary['data']);
+ $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']);
+ if (strpos($field_desc, '%s') !== false)
{
- continue;
+ $field_desc = sprintf($field_desc, $value);
+ }
+ $contact_url = '';
+ if (strpos($ident_ary['data']['field_contact_url'], '%s') !== false)
+ {
+ $contact_url = sprintf($ident_ary['data']['field_contact_url'], $value);
}
-
- $tpl_fields['row'] += array(
- 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
- 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
- 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
- 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']),
-
- 'S_PROFILE_' . strtoupper($ident) => true,
- );
-
- $tpl_fields['blockrow'][] = array(
- 'PROFILE_FIELD_VALUE' => $value,
- 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
- 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
- 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']),
-
- 'S_PROFILE_' . strtoupper($ident) => true,
- );
}
- return $tpl_fields;
- }
- else
- {
- trigger_error('Wrong mode for custom profile', E_USER_ERROR);
+ $tpl_fields['row'] += array(
+ 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident,
+ 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
+ 'PROFILE_' . strtoupper($ident) . '_CONTACT'=> $contact_url,
+ 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc,
+ 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
+ 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
+ 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']),
+
+ 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'],
+ 'S_PROFILE_' . strtoupper($ident) => true,
+ );
+
+ $tpl_fields['blockrow'][] = array(
+ 'PROFILE_FIELD_IDENT' => $ident,
+ 'PROFILE_FIELD_VALUE' => $value,
+ 'PROFILE_FIELD_CONTACT' => $contact_url,
+ 'PROFILE_FIELD_DESC' => $field_desc,
+ 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
+ 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
+ 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']),
+
+ 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'],
+ 'S_PROFILE_' . strtoupper($ident) => true,
+ );
}
+
+ return $tpl_fields;
}
/**
diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php
index 9c363a7b4e..a96196674d 100644
--- a/phpBB/phpbb/profilefields/type/type_base.php
+++ b/phpBB/phpbb/profilefields/type/type_base.php
@@ -87,6 +87,14 @@ abstract class type_base implements type_interface
/**
* {@inheritDoc}
*/
+ public function get_profile_contact_value($field_value, $field_data)
+ {
+ return $this->get_profile_value($field_value, $field_data);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function get_language_options_input($field_data)
{
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php
index fc012dd97a..af3d65c9b6 100644
--- a/phpBB/phpbb/profilefields/type/type_date.php
+++ b/phpBB/phpbb/profilefields/type/type_date.php
@@ -66,6 +66,7 @@ class type_date extends type_base
'field_ident' => 'field_default_value',
'field_type' => $this->get_service_name(),
'field_length' => $field_data['field_length'],
+ 'lang_options' => $field_data['lang_options'],
);
$always_now = request_var('always_now', -1);
diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php
index b89faca018..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' => '<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;
@@ -141,7 +141,7 @@ class type_int extends type_base
*/
public function get_profile_value($field_value, $field_data)
{
- if ($field_value === '' && !$field_data['field_show_novalue'])
+ if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
{
return null;
}
diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php
index 94f6882524..a1c3d879c8 100644
--- a/phpBB/phpbb/profilefields/type/type_interface.php
+++ b/phpBB/phpbb/profilefields/type/type_interface.php
@@ -90,6 +90,17 @@ interface type_interface
public function get_profile_value($field_value, $field_data);
/**
+ * Get Profile Value for display
+ *
+ * When displaying a contact field, we don't want to have links already parsed and more
+ *
+ * @param mixed $field_value Field value as stored in the database
+ * @param array $field_data Array with requirements of the field
+ * @return mixed Field value to display
+ */
+ public function get_profile_contact_value($field_value, $field_data);
+
+ /**
* Generate the input field for display
*
* @param array $profile_row Array with data for this field
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_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php
index f00a7e6a08..0738cbdafd 100644
--- a/phpBB/phpbb/profilefields/type/type_string_common.php
+++ b/phpBB/phpbb/profilefields/type/type_string_common.php
@@ -11,15 +11,21 @@ namespace phpbb\profilefields\type;
abstract class type_string_common extends type_base
{
+ protected $validation_options = array(
+ 'CHARS_ANY' => '.*',
+ 'NUMBERS_ONLY' => '[0-9]+',
+ 'ALPHA_ONLY' => '[\w]+',
+ 'ALPHA_UNDERSCORE' => '[\w_]+',
+ 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+',
+ );
+
/**
* Return possible validation options
*/
- function validate_options($field_data)
+ public function validate_options($field_data)
{
- $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+');
-
$validate_options = '';
- foreach ($validate_ary as $lang => $value)
+ foreach ($this->validation_options as $lang => $value)
{
$selected = ($field_data['field_validation'] == $value) ? ' selected="selected"' : '';
$validate_options .= '<option value="' . $value . '"' . $selected . '>' . $this->user->lang[$lang] . '</option>';
@@ -69,17 +75,12 @@ abstract class type_string_common extends type_base
$field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value);
if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
{
- switch ($row['field_validation'])
+ $validation = array_search($field_data['field_validation'], $this->validation_options);
+ if ($validation)
{
- case '[0-9]+':
- return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $this->get_field_name($field_data['lang_name']));
-
- case '[\w]+':
- return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $this->get_field_name($field_data['lang_name']));
-
- case '[\w_\+\. \-\[\]]+':
- return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $this->get_field_name($field_data['lang_name']));
+ return $this->user->lang('FIELD_INVALID_CHARS_' . $validation, $this->get_field_name($field_data['lang_name']));
}
+ return $this->user->lang('FIELD_INVALID_CHARS_INVALID', $this->get_field_name($field_data['lang_name']));
}
}
@@ -105,6 +106,19 @@ abstract class type_string_common extends type_base
/**
* {@inheritDoc}
*/
+ public function get_profile_contact_value($field_value, $field_data)
+ {
+ if (!$field_value && !$field_data['field_show_novalue'])
+ {
+ return null;
+ }
+
+ return $field_value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function prepare_options_form(&$exclude_options, &$visibility_options)
{
$exclude_options[1][] = 'lang_default_value';
diff --git a/phpBB/phpbb/profilefields/type/type_url.php b/phpBB/phpbb/profilefields/type/type_url.php
new file mode 100644
index 0000000000..b1523b9355
--- /dev/null
+++ b/phpBB/phpbb/profilefields/type/type_url.php
@@ -0,0 +1,70 @@
+<?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 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;
+ }
+}