1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-13 12:14:06 +02:00

Merge remote-tracking branch 'github-nickvergessen/ticket/12235' into develop

* github-nickvergessen/ticket/12235:
  [ticket/12235] Convert WLM to custom profile field
  [ticket/12187] Do not make clickable when using as contact field
  [ticket/12187] Split generate_profile_fields_template() into 2 methods
  [ticket/12187] Remove user_website field
  [ticket/12187] Remove user_website functionality
  [ticket/12187] Convert website field data to custom profile field
  [ticket/12187] Add URL type for profile fields
  [ticket/12234] Replace ICQ with custom profile field
  [ticket/12233] Update schema file
  [ticket/12233] Add images back to subsilver2
  [ticket/12233] Allow profile fields to be contact fields

Conflicts:
	phpBB/adm/style/acp_prune_users.html
This commit is contained in:
Nils Adermann
2014-03-05 11:49:11 +01:00
66 changed files with 766 additions and 536 deletions

View File

@@ -0,0 +1,51 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_contact_field extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return $this->db_tools->sql_column_exists($this->table_prefix . 'profile_fields', 'field_is_contact');
}
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\profilefield_on_memberlist',
);
}
public function update_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_is_contact' => array('BOOL', 0),
'field_contact_desc' => array('VCHAR', ''),
'field_contact_url' => array('VCHAR', ''),
),
),
);
}
public function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_is_contact',
'field_contact_desc',
'field_contact_url',
),
),
);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_icq extends \phpbb\db\migration\profilefield_base_migration
{
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\profilefield_contact_field',
);
}
protected $profilefield_name = 'phpbb_icq';
protected $profilefield_database_type = array('VCHAR', '');
protected $profilefield_data = array(
'field_name' => 'phpbb_icq',
'field_type' => 'profilefields.type.string',
'field_ident' => 'phpbb_icq',
'field_length' => '20',
'field_minlen' => '3',
'field_maxlen' => '15',
'field_novalue' => '',
'field_default_value' => '',
'field_validation' => '[0-9]+',
'field_required' => 0,
'field_show_novalue' => 0,
'field_show_on_reg' => 0,
'field_show_on_pm' => 1,
'field_show_on_vt' => 1,
'field_show_profile' => 1,
'field_hide' => 0,
'field_no_view' => 0,
'field_active' => 1,
'field_is_contact' => 1,
'field_contact_desc' => 'SEND_ICQ_MESSAGE',
'field_contact_url' => 'https://www.icq.com/people/%s/',
);
protected $user_column_name = 'user_icq';
}

View File

@@ -0,0 +1,47 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_icq_cleanup extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_icq');
}
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\profilefield_icq',
);
}
public function update_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'users' => array(
'user_icq',
),
),
);
}
public function revert_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'users' => array(
'user_icq' => array('VCHAR:20', ''),
),
),
);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_website extends \phpbb\db\migration\profilefield_base_migration
{
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\profilefield_on_memberlist',
'\phpbb\db\migration\data\v310\profilefield_icq_cleanup',
);
}
protected $profilefield_name = 'phpbb_website';
protected $profilefield_database_type = array('VCHAR', '');
protected $profilefield_data = array(
'field_name' => 'phpbb_website',
'field_type' => 'profilefields.type.url',
'field_ident' => 'phpbb_website',
'field_length' => '40',
'field_minlen' => '12',
'field_maxlen' => '255',
'field_novalue' => '',
'field_default_value' => '',
'field_validation' => '',
'field_required' => 0,
'field_show_novalue' => 0,
'field_show_on_reg' => 0,
'field_show_on_pm' => 1,
'field_show_on_vt' => 1,
'field_show_on_ml' => 1,
'field_show_profile' => 1,
'field_hide' => 0,
'field_no_view' => 0,
'field_active' => 1,
'field_is_contact' => 1,
'field_contact_desc' => 'VISIT_WEBSITE',
'field_contact_url' => '%s',
);
protected $user_column_name = 'user_website';
}

View File

@@ -0,0 +1,47 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_website_cleanup extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_website');
}
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\profilefield_website',
);
}
public function update_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'users' => array(
'user_website',
),
),
);
}
public function revert_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'users' => array(
'user_website' => array('VCHAR_UNI:200', ''),
),
),
);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_wlm extends \phpbb\db\migration\profilefield_base_migration
{
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\profilefield_website_cleanup',
);
}
protected $profilefield_name = 'phpbb_wlm';
protected $profilefield_database_type = array('VCHAR', '');
protected $profilefield_data = array(
'field_name' => 'phpbb_wlm',
'field_type' => 'profilefields.type.string',
'field_ident' => 'phpbb_wlm',
'field_length' => '40',
'field_minlen' => '5',
'field_maxlen' => '255',
'field_novalue' => '',
'field_default_value' => '',
'field_validation' => '.*',
'field_required' => 0,
'field_show_novalue' => 0,
'field_show_on_reg' => 0,
'field_show_on_pm' => 1,
'field_show_on_vt' => 1,
'field_show_on_ml' => 0,
'field_show_profile' => 1,
'field_hide' => 0,
'field_no_view' => 0,
'field_active' => 1,
'field_is_contact' => 1,
'field_contact_desc' => '',
'field_contact_url' => '',
);
protected $user_column_name = 'user_msnm';
}

View File

@@ -0,0 +1,47 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_wlm_cleanup extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_msnm');
}
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\profilefield_wlm',
);
}
public function update_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'users' => array(
'user_msnm',
),
),
);
}
public function revert_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'users' => array(
'user_msnm' => array('VCHAR_UNI', ''),
),
),
);
}
}

View File

@@ -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_ids = array($user_ids);
}
if (!sizeof($this->profile_cache))
{
$this->build_cache();
}
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_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);
$user_fields = array();
// Go through the fields in correct order
foreach (array_keys($this->profile_cache) as $used_ident)
{
foreach ($field_data as $user_id => $row)
{
$user_id = array($user_id);
$user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
$user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
}
if (!sizeof($this->profile_cache))
foreach ($user_ids as $user_id)
{
$this->build_cache();
}
if (!sizeof($user_id))
{
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);
$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_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)
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')
{
// $profile_row == $user_fields[$row['user_id']];
$tpl_fields = array();
$tpl_fields['row'] = $tpl_fields['blockrow'] = array();
foreach ($profile_row as $ident => $ident_ary)
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_field = $this->type_collection[$ident_ary['data']['field_type']];
$value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
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']);
if ($value === null)
{
continue;
}
$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,
);
continue;
}
return $tpl_fields;
}
else
{
trigger_error('Wrong mode for custom profile', E_USER_ERROR);
$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)
{
$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) . '_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;
}
/**

View File

@@ -84,6 +84,14 @@ abstract class type_base implements type_interface
return isset($this->user->lang[$field_name]) ? $this->user->lang[$field_name] : $field_name;
}
/**
* {@inheritDoc}
*/
public function get_profile_contact_value($field_value, $field_data)
{
return $this->get_profile_value($field_value, $field_data);
}
/**
* {@inheritDoc}
*/

View File

@@ -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;

View File

@@ -89,6 +89,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
*

View File

@@ -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));
}
/**

View File

@@ -102,6 +102,19 @@ abstract class type_string_common extends type_base
return $field_value;
}
/**
* {@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}
*/

View File

@@ -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;
}
}