[ticket/11201] Split language options into a new class

Otherwise we run into a circular dependency

PHPBB3-11201
This commit is contained in:
Joas Schilling 2014-01-15 11:40:03 +01:00
parent cd6bdc7b27
commit 5df7f76e6b
10 changed files with 180 additions and 85 deletions

View file

@ -5,14 +5,27 @@ services:
- @auth - @auth
- @dbal.conn - @dbal.conn
- @service_container - @service_container
#- @profilefields.type_collection
- @request - @request
- @template - @template
- @user - @user
profilefields.lang_helper:
class: \phpbb\profilefields\lang_helper
arguments:
- @dbal.conn
profilefields.type_collection:
class: phpbb\di\service_collection
arguments:
- @service_container
tags:
- { name: service_collection, tag: profilefield.type }
profilefields.type.bool: profilefields.type.bool:
class: \phpbb\profilefields\type\type_bool class: \phpbb\profilefields\type\type_bool
arguments: arguments:
- @profilefields - @profilefields.lang_helper
- @request - @request
- @template - @template
- @user - @user
@ -32,7 +45,7 @@ services:
profilefields.type.dropdown: profilefields.type.dropdown:
class: \phpbb\profilefields\type\type_dropdown class: \phpbb\profilefields\type\type_dropdown
arguments: arguments:
- @profilefields - @profilefields.lang_helper
- @request - @request
- @template - @template
- @user - @user

View file

@ -0,0 +1,114 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\profilefields;
/**
* Custom Profile Fields
* @package phpBB3
*/
class lang_helper
{
/**
* Array with the language option, grouped by field and language
* @var array
*/
protected $options_lang = array();
/**
* Database object
* @var \phpbb\db\driver\driver
*/
protected $db;
/**
* Construct
*
* @param \phpbb\db\driver\driver $db Database object
*/
public function __construct($db)
{
$this->db = $db;
}
/**
* Get language entries for options and store them here for later use
*/
public function get_option_lang($field_id, $lang_id, $field_type, $preview_options)
{
if ($preview_options !== false)
{
$lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options;
foreach ($lang_options as $num => $var)
{
$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
}
}
else
{
$sql = 'SELECT option_id, lang_value
FROM ' . PROFILE_FIELDS_LANG_TABLE . "
WHERE field_id = $field_id
AND lang_id = $lang_id
AND field_type = $field_type
ORDER BY option_id";
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
}
$this->db->sql_freeresult($result);
}
}
/**
* Are language options set for this field?
*
* @param int $field_id Database ID of the field
* @param int $lang_id ID of the language
* @param int $field_value Selected value of the field
* @return boolean
*/
public function is_set($field_id, $lang_id = null, $field_value = null)
{
$is_set = isset($this->lang_helper->options_lang[$field_id]);
if ($is_set && (!is_null($lang_id) || !is_null($field_value)))
{
$is_set = isset($this->lang_helper->options_lang[$field_id][$lang_id]);
}
if ($is_set && !is_null($field_value))
{
$is_set = isset($this->lang_helper->options_lang[$field_id][$lang_id][$field_value]);
}
return $is_set;
}
/**
* Get the selected language string
*
* @param int $field_id Database ID of the field
* @param int $lang_id ID of the language
* @param int $field_value Selected value of the field
* @return string
*/
public function get($field_id, $lang_id, $field_value = null)
{
if (!is_null($field_value))
{
return $this->lang_helper->options_lang[$field_id][$lang_id];
}
return $this->lang_helper->options_lang[$field_id][$lang_id][$field_value];
}
}

View file

@ -17,7 +17,6 @@ class profilefields
{ {
var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date'); var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date');
var $profile_cache = array(); var $profile_cache = array();
var $options_lang = array();
/** /**
* *
@ -110,38 +109,6 @@ class profilefields
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
} }
/**
* Get language entries for options and store them here for later use
*/
public function get_option_lang($field_id, $lang_id, $field_type, $preview)
{
if ($preview)
{
$lang_options = (!is_array($this->vars['lang_options'])) ? explode("\n", $this->vars['lang_options']) : $this->vars['lang_options'];
foreach ($lang_options as $num => $var)
{
$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
}
}
else
{
$sql = 'SELECT option_id, lang_value
FROM ' . PROFILE_FIELDS_LANG_TABLE . "
WHERE field_id = $field_id
AND lang_id = $lang_id
AND field_type = $field_type
ORDER BY option_id";
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
}
$this->db->sql_freeresult($result);
}
}
/** /**
* Submit profile field for validation * Submit profile field for validation
*/ */
@ -360,7 +327,7 @@ class profilefields
*/ */
protected function process_field_row($mode, $profile_row) protected function process_field_row($mode, $profile_row)
{ {
$preview = ($mode == 'preview') ? true : false; $preview_options = ($mode == 'preview') ? $this->vars['lang_options'] : false;
// set template filename // set template filename
$this->template->set_filenames(array( $this->template->set_filenames(array(
@ -375,7 +342,7 @@ class profilefields
// Assign template variables // Assign template variables
$profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$profile_row['field_type']]); $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$profile_row['field_type']]);
$profile_field->generate_field($profile_row, $preview); $profile_field->generate_field($profile_row, $preview_options);
// Return templated data // Return templated data
return $this->template->assign_display('cp_body'); return $this->template->assign_display('cp_body');

View file

@ -14,9 +14,9 @@ class type_bool implements type_interface
/** /**
* *
*/ */
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
{ {
$this->profilefields = $profilefields; $this->lang_helper = $lang_helper;
$this->request = $request; $this->request = $request;
$this->template = $template; $this->template = $template;
$this->user = $user; $this->user = $user;
@ -42,7 +42,7 @@ class type_bool implements type_interface
$options = array( $options = array(
0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<label><input type="radio" class="radio" name="field_length" value="1"' . (($field_data['field_length'] == 1) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['RADIO_BUTTONS'] . '</label><label><input type="radio" class="radio" name="field_length" value="2"' . (($field_data['field_length'] == 2) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['CHECKBOX'] . '</label>'), 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<label><input type="radio" class="radio" name="field_length" value="1"' . (($field_data['field_length'] == 1) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['RADIO_BUTTONS'] . '</label><label><input type="radio" class="radio" name="field_length" value="2"' . (($field_data['field_length'] == 2) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['CHECKBOX'] . '</label>'),
1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)) 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)),
); );
return $options; return $options;
@ -112,9 +112,9 @@ class type_bool implements type_interface
$field_id = $field_data['field_id']; $field_id = $field_data['field_id'];
$lang_id = $field_data['lang_id']; $lang_id = $field_data['lang_id'];
if (!isset($this->profilefields->options_lang[$field_id][$lang_id])) if (!$this->lang_helper->is_set($field_id, $lang_id))
{ {
$this->profilefields->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
} }
if (!$field_value && $field_data['field_show_novalue']) if (!$field_value && $field_data['field_show_novalue'])
@ -124,7 +124,7 @@ class type_bool implements type_interface
if ($field_data['field_length'] == 1) if ($field_data['field_length'] == 1)
{ {
return (isset($this->profilefields->options_lang[$field_id][$lang_id][(int) $field_value])) ? $this->options_lang[$field_id][$lang_id][(int) $field_value] : null; return ($this->lang_helper->is_set($field_id, $lang_id, (int) $field_value)) ? $this->lang_helper->get($field_id, $lang_id, (int) $field_value) : null;
} }
else if (!$field_value) else if (!$field_value)
{ {
@ -132,28 +132,27 @@ class type_bool implements type_interface
} }
else else
{ {
return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1]; return $this->lang_helper->is_set($field_id, $lang_id, $field_value + 1);
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function generate_field($profile_row, $preview = false) public function generate_field($profile_row, $preview_options = false)
{ {
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident']; $field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value']; $default_value = $profile_row['lang_default_value'];
$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
// checkbox - set the value to "true" if it has been set to 1 // checkbox - set the value to "true" if it has been set to 1
if ($profile_row['field_length'] == 2) if ($profile_row['field_length'] == 2)
{ {
$value = ($this->request->is_set($field_ident) && $this->request->variable($field_ident, $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]); $value = ($this->request->is_set($field_ident) && $this->request->variable($field_ident, $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]);
} }
else else
{ {
$value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]); $value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]);
} }
$profile_row['field_value'] = (int) $value; $profile_row['field_value'] = (int) $value;
@ -161,12 +160,13 @@ class type_bool implements type_interface
if ($profile_row['field_length'] == 1) if ($profile_row['field_length'] == 1)
{ {
if (!isset($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1))
{ {
$this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview); $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview_options);
} }
foreach ($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']);
foreach ($options as $option_id => $option_value)
{ {
$this->template->assign_block_vars('bool.options', array( $this->template->assign_block_vars('bool.options', array(
'OPTION_ID' => $option_id, 'OPTION_ID' => $option_id,

View file

@ -35,7 +35,7 @@ class type_date implements type_interface
'field_default_value' => $field_data['field_default_value'], 'field_default_value' => $field_data['field_default_value'],
'field_ident' => 'field_default_value', 'field_ident' => 'field_default_value',
'field_type' => FIELD_DATE, 'field_type' => FIELD_DATE,
'field_length' => $field_data['field_length'] 'field_length' => $field_data['field_length'],
); );
$always_now = request_var('always_now', -1); $always_now = request_var('always_now', -1);
@ -174,7 +174,7 @@ class type_date implements type_interface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function generate_field($profile_row, $preview = false) public function generate_field($profile_row, $preview_options = false)
{ {
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
@ -186,14 +186,14 @@ class type_date implements type_interface
{ {
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
} }
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
} }
else else
{ {
if ($preview && $profile_row['field_default_value'] == 'now') if ($preview_options !== false && $profile_row['field_default_value'] == 'now')
{ {
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
} }
else else
{ {

View file

@ -14,9 +14,9 @@ class type_dropdown implements type_interface
/** /**
* *
*/ */
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
{ {
$this->profilefields = $profilefields; $this->lang_helper = $lang_helper;
$this->request = $request; $this->request = $request;
$this->template = $template; $this->template = $template;
$this->user = $user; $this->user = $user;
@ -36,7 +36,7 @@ class type_dropdown implements type_interface
'field_default_value' => $field_data['field_default_value'], 'field_default_value' => $field_data['field_default_value'],
'field_ident' => 'field_default_value', 'field_ident' => 'field_default_value',
'field_type' => FIELD_DROPDOWN, 'field_type' => FIELD_DROPDOWN,
'lang_options' => $field_data['lang_options'] 'lang_options' => $field_data['lang_options'],
); );
$profile_row[1] = $profile_row[0]; $profile_row[1] = $profile_row[0];
@ -46,7 +46,7 @@ class type_dropdown implements type_interface
$options = array( $options = array(
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[0])), 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[0])),
1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[1])) 1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[1])),
); );
return $options; return $options;
@ -92,12 +92,12 @@ class type_dropdown implements type_interface
$field_value = (int) $field_value; $field_value = (int) $field_value;
// retrieve option lang data if necessary // retrieve option lang data if necessary
if (!isset($this->profilefields->options_lang[$field_data['field_id']]) || !isset($this->profilefields->options_lang[$field_data['field_id']][$field_data['lang_id']]) || !sizeof($this->profilefields->options_lang[$file_data['field_id']][$field_data['lang_id']])) if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1))
{ {
$this->profilefields->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false);
} }
if (!isset($this->profilefields->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value])) if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value))
{ {
return $this->user->lang('FIELD_INVALID_VALUE', $field_data['lang_name']); return $this->user->lang('FIELD_INVALID_VALUE', $field_data['lang_name']);
} }
@ -117,9 +117,9 @@ class type_dropdown implements type_interface
{ {
$field_id = $field_data['field_id']; $field_id = $field_data['field_id'];
$lang_id = $field_data['lang_id']; $lang_id = $field_data['lang_id'];
if (!isset($this->profilefields->options_lang[$field_id][$lang_id])) if (!$this->lang_helper->is_set($field_id, $lang_id))
{ {
$this->profilefields->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
} }
if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
@ -130,7 +130,7 @@ class type_dropdown implements type_interface
$field_value = (int) $field_value; $field_value = (int) $field_value;
// User not having a value assigned // User not having a value assigned
if (!isset($this->profilefields->options_lang[$field_id][$lang_id][$field_value])) if (!$this->lang_helper->is_set($field_id, $lang_id, $field_value))
{ {
if ($field_data['field_show_novalue']) if ($field_data['field_show_novalue'])
{ {
@ -142,29 +142,30 @@ class type_dropdown implements type_interface
} }
} }
return $this->profilefields->options_lang[$field_id][$lang_id][$field_value]; return $this->lang_helper->get($field_id, $lang_id, $field_value);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function generate_field($profile_row, $preview = false) public function generate_field($profile_row, $preview_options = false)
{ {
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident']; $field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value']; $default_value = $profile_row['lang_default_value'];
$value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]); $value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]);
if (!isset($this->profilefields->options_lang[$profile_row['field_id']]) || !isset($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1))
{ {
$this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview); $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview_options);
} }
$profile_row['field_value'] = (int) $value; $profile_row['field_value'] = (int) $value;
$this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER)); $this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER));
foreach ($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']);
foreach ($options as $option_id => $option_value)
{ {
$this->template->assign_block_vars('dropdown.options', array( $this->template->assign_block_vars('dropdown.options', array(
'OPTION_ID' => $option_id, 'OPTION_ID' => $option_id,

View file

@ -30,7 +30,7 @@ class type_int implements type_interface
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'] . '" />'), 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'] . '" />'), 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'] . '" />'), 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="post" name="field_default_value" value="' . $field_data['field_default_value'] . '" />'),
); );
return $options; return $options;
@ -120,7 +120,7 @@ class type_int implements type_interface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function generate_field($profile_row, $preview = false) public function generate_field($profile_row, $preview_options = false)
{ {
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident']; $field_ident = $profile_row['field_ident'];
@ -132,11 +132,11 @@ class type_int implements type_interface
} }
else else
{ {
if (!$preview && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident])) if ($preview_options === false && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident]))
{ {
$value = null; $value = null;
} }
else if (!isset($this->user->profile_fields[$field_ident]) || $preview) else if (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false)
{ {
$value = $default_value; $value = $default_value;
} }

View file

@ -75,10 +75,10 @@ interface type_interface
* Generate the input field for display * Generate the input field for display
* *
* @param array $profile_row Array with data for this field * @param array $profile_row Array with data for this field
* @param bool $preview Do we preview the form * @param mixed $preview_options When previewing we use different data
* @return null * @return null
*/ */
public function generate_field($profile_row, $preview = false); public function generate_field($profile_row, $preview_options = false);
/** /**
* Get the ident of the field * Get the ident of the field

View file

@ -30,7 +30,7 @@ class type_string extends type_string_common implements type_interface
0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" name="field_length" size="5" value="' . $field_data['field_length'] . '" />'), 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'] . '" />'), 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" size="5" value="' . $field_data['field_maxlen'] . '" />'), 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" size="5" value="' . $field_data['field_maxlen'] . '" />'),
3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>') 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>'),
); );
return $options; return $options;
@ -71,12 +71,12 @@ class type_string extends type_string_common implements type_interface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function generate_field($profile_row, $preview = false) public function generate_field($profile_row, $preview_options = false)
{ {
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident']; $field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value']; $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) ? $default_value : $this->user->profile_fields[$field_ident]); $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('string', array_change_key_case($profile_row, CASE_UPPER));

View file

@ -30,7 +30,7 @@ class type_text extends type_string_common implements type_interface
0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="rows" size="5" value="' . $field_data['rows'] . '" /> ' . $this->user->lang['ROWS'] . '</dd><dd><input type="number" min="0" max="99999" name="columns" size="5" value="' . $field_data['columns'] . '" /> ' . $this->user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $field_data['field_length'] . '" />'), 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="rows" size="5" value="' . $field_data['rows'] . '" /> ' . $this->user->lang['ROWS'] . '</dd><dd><input type="number" min="0" max="99999" name="columns" size="5" value="' . $field_data['columns'] . '" /> ' . $this->user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $field_data['field_length'] . '" />'),
1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_minlen" size="10" value="' . $field_data['field_minlen'] . '" />'), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_minlen" size="10" value="' . $field_data['field_minlen'] . '" />'),
2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_maxlen" size="10" value="' . $field_data['field_maxlen'] . '" />'), 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_maxlen" size="10" value="' . $field_data['field_maxlen'] . '" />'),
3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>') 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>'),
); );
return $options; return $options;
@ -71,7 +71,7 @@ class type_text extends type_string_common implements type_interface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function generate_field($profile_row, $preview = false) public function generate_field($profile_row, $preview_options = false)
{ {
$field_length = explode('|', $profile_row['field_length']); $field_length = explode('|', $profile_row['field_length']);
$profile_row['field_rows'] = $field_length[0]; $profile_row['field_rows'] = $field_length[0];
@ -80,7 +80,7 @@ class type_text extends type_string_common implements type_interface
$field_ident = $profile_row['field_ident']; $field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value']; $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) ? $default_value : $this->user->profile_fields[$field_ident]); $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('text', array_change_key_case($profile_row, CASE_UPPER)); $this->template->assign_block_vars('text', array_change_key_case($profile_row, CASE_UPPER));
} }