mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-29 06:38:52 +00:00
[ticket/11201] Move get_options to type classes
PHPBB3-11201
This commit is contained in:
parent
c665839636
commit
a7e3538e5b
11 changed files with 471 additions and 217 deletions
|
@ -8,17 +8,47 @@ services:
|
||||||
- @template
|
- @template
|
||||||
- @user
|
- @user
|
||||||
|
|
||||||
profilefields.admin:
|
profilefields.type.bool:
|
||||||
class: \phpbb\profilefields\admin
|
class: \phpbb\profilefields\type\type_bool
|
||||||
arguments:
|
arguments:
|
||||||
- @auth
|
- @profilefields
|
||||||
- @config
|
|
||||||
- @dbal.conn
|
|
||||||
- @request
|
|
||||||
- @template
|
|
||||||
- @user
|
- @user
|
||||||
|
tags:
|
||||||
|
- { name: profilefield.type }
|
||||||
|
|
||||||
#migrator.tool.permission1:
|
profilefields.type.date:
|
||||||
# class: \phpbb\profilefields\profilefields
|
class: \phpbb\profilefields\type\type_date
|
||||||
# tags:
|
arguments:
|
||||||
# - { name: ffoobar.tool }
|
- @profilefields
|
||||||
|
- @user
|
||||||
|
tags:
|
||||||
|
- { name: profilefield.type }
|
||||||
|
|
||||||
|
profilefields.type.dropdown:
|
||||||
|
class: \phpbb\profilefields\type\type_dropdown
|
||||||
|
arguments:
|
||||||
|
- @profilefields
|
||||||
|
- @user
|
||||||
|
tags:
|
||||||
|
- { name: profilefield.type }
|
||||||
|
|
||||||
|
profilefields.type.int:
|
||||||
|
class: \phpbb\profilefields\type\type_int
|
||||||
|
arguments:
|
||||||
|
- @user
|
||||||
|
tags:
|
||||||
|
- { name: profilefield.type }
|
||||||
|
|
||||||
|
profilefields.type.string:
|
||||||
|
class: \phpbb\profilefields\type\type_string
|
||||||
|
arguments:
|
||||||
|
- @user
|
||||||
|
tags:
|
||||||
|
- { name: profilefield.type }
|
||||||
|
|
||||||
|
profilefields.type.text:
|
||||||
|
class: \phpbb\profilefields\type\type_text
|
||||||
|
arguments:
|
||||||
|
- @user
|
||||||
|
tags:
|
||||||
|
- { name: profilefield.type }
|
||||||
|
|
|
@ -49,17 +49,7 @@ class acp_profile
|
||||||
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define some default values for each field type
|
$cp = $phpbb_container->get('profilefields');
|
||||||
$default_values = array(
|
|
||||||
FIELD_STRING => array('field_length' => 10, 'field_minlen' => 0, 'field_maxlen' => 20, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
|
|
||||||
FIELD_TEXT => array('field_length' => '5|80', 'field_minlen' => 0, 'field_maxlen' => 1000, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
|
|
||||||
FIELD_INT => array('field_length' => 5, 'field_minlen' => 0, 'field_maxlen' => 100, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
|
|
||||||
FIELD_DATE => array('field_length' => 10, 'field_minlen' => 10, 'field_maxlen' => 10, 'field_validation' => '', 'field_novalue' => ' 0- 0- 0', 'field_default_value' => ' 0- 0- 0'),
|
|
||||||
FIELD_BOOL => array('field_length' => 1, 'field_minlen' => 0, 'field_maxlen' => 0, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
|
|
||||||
FIELD_DROPDOWN => array('field_length' => 0, 'field_minlen' => 0, 'field_maxlen' => 5, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
|
|
||||||
);
|
|
||||||
|
|
||||||
$cp = $phpbb_container->get('profilefields.admin');
|
|
||||||
|
|
||||||
// Build Language array
|
// Build Language array
|
||||||
// Based on this, we decide which elements need to be edited later and which language items are missing
|
// Based on this, we decide which elements need to be edited later and which language items are missing
|
||||||
|
@ -93,10 +83,10 @@ class acp_profile
|
||||||
// Have some fields been defined?
|
// Have some fields been defined?
|
||||||
if (isset($this->lang_defs['entry']))
|
if (isset($this->lang_defs['entry']))
|
||||||
{
|
{
|
||||||
foreach ($this->lang_defs['entry'] as $field_id => $field_ary)
|
foreach ($this->lang_defs['entry'] as $field_ident => $field_ary)
|
||||||
{
|
{
|
||||||
// Fill an array with the languages that are missing for each field
|
// Fill an array with the languages that are missing for each field
|
||||||
$this->lang_defs['diff'][$field_id] = array_diff(array_values($this->lang_defs['iso']), $field_ary);
|
$this->lang_defs['diff'][$field_ident] = array_diff(array_values($this->lang_defs['iso']), $field_ary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,7 +371,8 @@ class acp_profile
|
||||||
trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
$field_row = array_merge($default_values[$field_type], array(
|
$profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]);
|
||||||
|
$field_row = array_merge($profile_field->get_default_values(), array(
|
||||||
'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))),
|
'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))),
|
||||||
'field_required' => 0,
|
'field_required' => 0,
|
||||||
'field_show_novalue'=> 0,
|
'field_show_novalue'=> 0,
|
||||||
|
@ -848,8 +839,8 @@ class acp_profile
|
||||||
);
|
);
|
||||||
|
|
||||||
// Build options based on profile type
|
// Build options based on profile type
|
||||||
$function = 'get_' . $cp->profile_types[$field_type] . '_options';
|
$profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]);
|
||||||
$options = $cp->$function($this->lang_defs);
|
$options = $profile_field->get_options($this->lang_defs, $cp->vars);
|
||||||
|
|
||||||
foreach ($options as $num => $option_ary)
|
foreach ($options as $num => $option_ary)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,190 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package phpBB3
|
|
||||||
* @copyright (c) 2005 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpbb\profilefields;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom Profile Fields ACP
|
|
||||||
* @package phpBB3
|
|
||||||
*/
|
|
||||||
class admin extends profilefields
|
|
||||||
{
|
|
||||||
var $vars = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function __construct($auth, $config, $db, $request, $template, $user)
|
|
||||||
{
|
|
||||||
$this->auth = $auth;
|
|
||||||
$this->config = $config;
|
|
||||||
$this->db = $db;
|
|
||||||
$this->request = $request;
|
|
||||||
$this->template = $template;
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return possible validation options
|
|
||||||
*/
|
|
||||||
function validate_options()
|
|
||||||
{
|
|
||||||
$validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+');
|
|
||||||
|
|
||||||
$validate_options = '';
|
|
||||||
foreach ($validate_ary as $lang => $value)
|
|
||||||
{
|
|
||||||
$selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : '';
|
|
||||||
$validate_options .= '<option value="' . $value . '"' . $selected . '>' . $this->user->lang[$lang] . '</option>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $validate_options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string options for second step in ACP
|
|
||||||
*/
|
|
||||||
function get_string_options($lang_defs)
|
|
||||||
{
|
|
||||||
$options = array(
|
|
||||||
0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
|
|
||||||
1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
|
|
||||||
2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
|
|
||||||
3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get text options for second step in ACP
|
|
||||||
*/
|
|
||||||
function get_text_options($lang_defs)
|
|
||||||
{
|
|
||||||
$options = array(
|
|
||||||
0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="rows" size="5" value="' . $this->vars['rows'] . '" /> ' . $user->lang['ROWS'] . '</dd><dd><input type="number" min="0" max="99999" name="columns" size="5" value="' . $this->vars['columns'] . '" /> ' . $user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $this->vars['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="' . $this->vars['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="' . $this->vars['field_maxlen'] . '" />'),
|
|
||||||
3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get int options for second step in ACP
|
|
||||||
*/
|
|
||||||
function get_int_options($lang_defs)
|
|
||||||
{
|
|
||||||
$options = array(
|
|
||||||
0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_length" size="5" value="' . $this->vars['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="' . $this->vars['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="' . $this->vars['field_maxlen'] . '" />'),
|
|
||||||
3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get bool options for second step in ACP
|
|
||||||
*/
|
|
||||||
function get_bool_options($lang_defs)
|
|
||||||
{
|
|
||||||
$default_lang_id = $lang_defs['iso'][$this->config['default_lang']];
|
|
||||||
|
|
||||||
$profile_row = array(
|
|
||||||
'var_name' => 'field_default_value',
|
|
||||||
'field_id' => 1,
|
|
||||||
'lang_name' => $this->vars['lang_name'],
|
|
||||||
'lang_explain' => $this->vars['lang_explain'],
|
|
||||||
'lang_id' => $default_lang_id,
|
|
||||||
'field_default_value' => $this->vars['field_default_value'],
|
|
||||||
'field_ident' => 'field_default_value',
|
|
||||||
'field_type' => FIELD_BOOL,
|
|
||||||
'field_length' => $this->vars['field_length'],
|
|
||||||
'lang_options' => $this->vars['lang_options']
|
|
||||||
);
|
|
||||||
|
|
||||||
$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"' . (($this->vars['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"' . (($this->vars['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->process_field_row('preview', $profile_row))
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get dropdown options for second step in ACP
|
|
||||||
*/
|
|
||||||
function get_dropdown_options($lang_defs)
|
|
||||||
{
|
|
||||||
$default_lang_id = $lang_defs['iso'][$this->config['default_lang']];
|
|
||||||
|
|
||||||
$profile_row[0] = array(
|
|
||||||
'var_name' => 'field_default_value',
|
|
||||||
'field_id' => 1,
|
|
||||||
'lang_name' => $this->vars['lang_name'],
|
|
||||||
'lang_explain' => $this->vars['lang_explain'],
|
|
||||||
'lang_id' => $default_lang_id,
|
|
||||||
'field_default_value' => $this->vars['field_default_value'],
|
|
||||||
'field_ident' => 'field_default_value',
|
|
||||||
'field_type' => FIELD_DROPDOWN,
|
|
||||||
'lang_options' => $this->vars['lang_options']
|
|
||||||
);
|
|
||||||
|
|
||||||
$profile_row[1] = $profile_row[0];
|
|
||||||
$profile_row[1]['var_name'] = 'field_novalue';
|
|
||||||
$profile_row[1]['field_ident'] = 'field_novalue';
|
|
||||||
$profile_row[1]['field_default_value'] = $this->vars['field_novalue'];
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->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->process_field_row('preview', $profile_row[1]))
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get date options for second step in ACP
|
|
||||||
*/
|
|
||||||
function get_date_options($lang_defs)
|
|
||||||
{
|
|
||||||
$default_lang_id = $lang_defs['iso'][$this->config['default_lang']];
|
|
||||||
|
|
||||||
$profile_row = array(
|
|
||||||
'var_name' => 'field_default_value',
|
|
||||||
'lang_name' => $this->vars['lang_name'],
|
|
||||||
'lang_explain' => $this->vars['lang_explain'],
|
|
||||||
'lang_id' => $default_lang_id,
|
|
||||||
'field_default_value' => $this->vars['field_default_value'],
|
|
||||||
'field_ident' => 'field_default_value',
|
|
||||||
'field_type' => FIELD_DATE,
|
|
||||||
'field_length' => $this->vars['field_length']
|
|
||||||
);
|
|
||||||
|
|
||||||
$always_now = request_var('always_now', -1);
|
|
||||||
if ($always_now == -1)
|
|
||||||
{
|
|
||||||
$s_checked = ($this->vars['field_default_value'] == 'now') ? true : false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$s_checked = ($always_now) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)),
|
|
||||||
1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => '<label><input type="radio" class="radio" name="always_now" value="1"' . (($s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['YES'] . '</label><label><input type="radio" class="radio" name="always_now" value="0"' . ((!$s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['NO'] . '</label>'),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
}
|
|
63
phpBB/phpbb/profilefields/type/type_bool.php
Normal file
63
phpBB/phpbb/profilefields/type/type_bool.php
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<?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_bool implements type_interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
|
||||||
|
{
|
||||||
|
$this->profilefields = $profilefields;
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_options($default_lang_id, $field_data)
|
||||||
|
{
|
||||||
|
$profile_row = array(
|
||||||
|
'var_name' => 'field_default_value',
|
||||||
|
'field_id' => 1,
|
||||||
|
'lang_name' => $field_data['lang_name'],
|
||||||
|
'lang_explain' => $field_data['lang_explain'],
|
||||||
|
'lang_id' => $default_lang_id,
|
||||||
|
'field_default_value' => $field_data['field_default_value'],
|
||||||
|
'field_ident' => 'field_default_value',
|
||||||
|
'field_type' => FIELD_BOOL,
|
||||||
|
'field_length' => $field_data['field_length'],
|
||||||
|
'lang_options' => $field_data['lang_options']
|
||||||
|
);
|
||||||
|
|
||||||
|
$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>'),
|
||||||
|
1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row))
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_default_values()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'field_length' => 1,
|
||||||
|
'field_minlen' => 0,
|
||||||
|
'field_maxlen' => 0,
|
||||||
|
'field_validation' => '',
|
||||||
|
'field_novalue' => 0,
|
||||||
|
'field_default_value' => 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
71
phpBB/phpbb/profilefields/type/type_date.php
Normal file
71
phpBB/phpbb/profilefields/type/type_date.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?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_date implements type_interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
|
||||||
|
{
|
||||||
|
$this->profilefields = $profilefields;
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_options($default_lang_id, $field_data)
|
||||||
|
{
|
||||||
|
$profile_row = array(
|
||||||
|
'var_name' => 'field_default_value',
|
||||||
|
'lang_name' => $field_data['lang_name'],
|
||||||
|
'lang_explain' => $field_data['lang_explain'],
|
||||||
|
'lang_id' => $default_lang_id,
|
||||||
|
'field_default_value' => $field_data['field_default_value'],
|
||||||
|
'field_ident' => 'field_default_value',
|
||||||
|
'field_type' => FIELD_DATE,
|
||||||
|
'field_length' => $field_data['field_length']
|
||||||
|
);
|
||||||
|
|
||||||
|
$always_now = request_var('always_now', -1);
|
||||||
|
if ($always_now == -1)
|
||||||
|
{
|
||||||
|
$s_checked = ($field_data['field_default_value'] == 'now') ? true : false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$s_checked = ($always_now) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = array(
|
||||||
|
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)),
|
||||||
|
1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => '<label><input type="radio" class="radio" name="always_now" value="1"' . (($s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['YES'] . '</label><label><input type="radio" class="radio" name="always_now" value="0"' . ((!$s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['NO'] . '</label>'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_default_values()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'field_length' => 10,
|
||||||
|
'field_minlen' => 10,
|
||||||
|
'field_maxlen' => 10,
|
||||||
|
'field_validation' => '',
|
||||||
|
'field_novalue' => ' 0- 0- 0',
|
||||||
|
'field_default_value' => ' 0- 0- 0',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
67
phpBB/phpbb/profilefields/type/type_dropdown.php
Normal file
67
phpBB/phpbb/profilefields/type/type_dropdown.php
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?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_dropdown implements type_interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
|
||||||
|
{
|
||||||
|
$this->profilefields = $profilefields;
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_options($default_lang_id, $field_data)
|
||||||
|
{
|
||||||
|
$profile_row[0] = array(
|
||||||
|
'var_name' => 'field_default_value',
|
||||||
|
'field_id' => 1,
|
||||||
|
'lang_name' => $field_data['lang_name'],
|
||||||
|
'lang_explain' => $field_data['lang_explain'],
|
||||||
|
'lang_id' => $default_lang_id,
|
||||||
|
'field_default_value' => $field_data['field_default_value'],
|
||||||
|
'field_ident' => 'field_default_value',
|
||||||
|
'field_type' => FIELD_DROPDOWN,
|
||||||
|
'lang_options' => $field_data['lang_options']
|
||||||
|
);
|
||||||
|
|
||||||
|
$profile_row[1] = $profile_row[0];
|
||||||
|
$profile_row[1]['var_name'] = 'field_novalue';
|
||||||
|
$profile_row[1]['field_ident'] = 'field_novalue';
|
||||||
|
$profile_row[1]['field_default_value'] = $field_data['field_novalue'];
|
||||||
|
|
||||||
|
$options = array(
|
||||||
|
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]))
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_default_values()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'field_length' => 0,
|
||||||
|
'field_minlen' => 0,
|
||||||
|
'field_maxlen' => 5,
|
||||||
|
'field_validation' => '',
|
||||||
|
'field_novalue' => 0,
|
||||||
|
'field_default_value' => 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
51
phpBB/phpbb/profilefields/type/type_int.php
Normal file
51
phpBB/phpbb/profilefields/type/type_int.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?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_int implements type_interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct($user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@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" 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'] . '" />')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_default_values()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'field_length' => 5,
|
||||||
|
'field_minlen' => 0,
|
||||||
|
'field_maxlen' => 100,
|
||||||
|
'field_validation' => '',
|
||||||
|
'field_novalue' => 0,
|
||||||
|
'field_default_value' => 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
39
phpBB/phpbb/profilefields/type/type_interface.php
Normal file
39
phpBB/phpbb/profilefields/type/type_interface.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?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;
|
||||||
|
|
||||||
|
interface type_interface
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
public function validate(&$value, $validation);
|
||||||
|
|
||||||
|
public function prepare_for_storage($value);
|
||||||
|
|
||||||
|
public function prepare_for_display($value);
|
||||||
|
|
||||||
|
public function prepare_for_edit($value);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get dropdown options for second step in ACP
|
||||||
|
*
|
||||||
|
* @param string $default_lang_id ID of the default language
|
||||||
|
* @param array $field_data Array with data for this field
|
||||||
|
* @return array with the acp options
|
||||||
|
*/
|
||||||
|
public function get_options($default_lang_id, $field_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default values for this type
|
||||||
|
*
|
||||||
|
* @return array with values like default field size and more
|
||||||
|
*/
|
||||||
|
public function get_default_values();
|
||||||
|
}
|
51
phpBB/phpbb/profilefields/type/type_string.php
Normal file
51
phpBB/phpbb/profilefields/type/type_string.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?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_string extends type_string_common implements type_interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct($user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@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" 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>')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_default_values()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'field_length' => 10,
|
||||||
|
'field_minlen' => 0,
|
||||||
|
'field_maxlen' => 20,
|
||||||
|
'field_validation' => '.*',
|
||||||
|
'field_novalue' => '',
|
||||||
|
'field_default_value' => '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
30
phpBB/phpbb/profilefields/type/type_string_common.php
Normal file
30
phpBB/phpbb/profilefields/type/type_string_common.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?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;
|
||||||
|
|
||||||
|
abstract class type_string_common
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Return possible validation options
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
$selected = ($field_data['field_validation'] == $value) ? ' selected="selected"' : '';
|
||||||
|
$validate_options .= '<option value="' . $value . '"' . $selected . '>' . $this->user->lang[$lang] . '</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $validate_options;
|
||||||
|
}
|
||||||
|
}
|
51
phpBB/phpbb/profilefields/type/type_text.php
Normal file
51
phpBB/phpbb/profilefields/type/type_text.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?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_text extends type_string_common implements type_interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct($user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@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" 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'] . '" />'),
|
||||||
|
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>')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_default_values()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'field_length' => '5|80',
|
||||||
|
'field_minlen' => 0,
|
||||||
|
'field_maxlen' => 1000,
|
||||||
|
'field_validation' => '.*',
|
||||||
|
'field_novalue' => '',
|
||||||
|
'field_default_value' => '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue