PDF rausgenommen
This commit is contained in:
140
msd2/phpBB3/phpbb/profilefields/lang_helper.php
Normal file
140
msd2/phpBB3/phpbb/profilefields/lang_helper.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields;
|
||||
|
||||
/**
|
||||
* Custom Profile Fields
|
||||
*/
|
||||
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_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Table where the language strings are stored
|
||||
* @var string
|
||||
*/
|
||||
protected $language_table;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
||||
* @param string $language_table Table where the language strings are stored
|
||||
*/
|
||||
public function __construct($db, $language_table)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->language_table = $language_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads preview options into language entries for options
|
||||
*
|
||||
* @param int $field_id
|
||||
* @param int $lang_id
|
||||
* @param mixed $preview_options
|
||||
*/
|
||||
public function load_preview_options($field_id, $lang_id, $preview_options)
|
||||
{
|
||||
$lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options;
|
||||
|
||||
foreach ($lang_options as $num => $var)
|
||||
{
|
||||
if (!isset($this->options_lang[$field_id]))
|
||||
{
|
||||
$this->options_lang[$field_id] = array();
|
||||
}
|
||||
if (!isset($this->options_lang[$field_id][$lang_id]))
|
||||
{
|
||||
$this->options_lang[$field_id][$lang_id] = array();
|
||||
}
|
||||
$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches language entries for options from DB
|
||||
*
|
||||
* @param int $lang_id
|
||||
*/
|
||||
public function load_option_lang($lang_id)
|
||||
{
|
||||
$sql = 'SELECT field_id, option_id, lang_value
|
||||
FROM ' . $this->language_table . '
|
||||
WHERE lang_id = ' . (int) $lang_id . "
|
||||
ORDER BY option_id";
|
||||
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$this->options_lang[$row['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->options_lang[$field_id]);
|
||||
|
||||
if ($is_set && (!is_null($lang_id) || !is_null($field_value)))
|
||||
{
|
||||
$is_set = isset($this->options_lang[$field_id][$lang_id]);
|
||||
}
|
||||
|
||||
if ($is_set && !is_null($field_value))
|
||||
{
|
||||
$is_set = isset($this->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->options_lang[$field_id][$lang_id];
|
||||
}
|
||||
|
||||
return $this->options_lang[$field_id][$lang_id][$field_value];
|
||||
}
|
||||
}
|
502
msd2/phpBB3/phpbb/profilefields/manager.php
Normal file
502
msd2/phpBB3/phpbb/profilefields/manager.php
Normal file
@ -0,0 +1,502 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields;
|
||||
|
||||
/**
|
||||
* Custom Profile Fields
|
||||
*/
|
||||
class manager
|
||||
{
|
||||
/**
|
||||
* Auth object
|
||||
* @var \phpbb\auth\auth
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Database object
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Event dispatcher object
|
||||
* @var \phpbb\event\dispatcher_interface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* Service Collection object
|
||||
* @var \phpbb\di\service_collection
|
||||
*/
|
||||
protected $type_collection;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
protected $fields_table;
|
||||
|
||||
protected $fields_language_table;
|
||||
|
||||
protected $fields_data_table;
|
||||
|
||||
protected $profile_cache = array();
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
||||
* @param \phpbb\event\dispatcher_interface $dispatcher Event dispatcher object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\di\service_collection $type_collection
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $fields_table
|
||||
* @param string $fields_language_table
|
||||
* @param string $fields_data_table
|
||||
*/
|
||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->db = $db;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->type_collection = $type_collection;
|
||||
$this->user = $user;
|
||||
|
||||
$this->fields_table = $fields_table;
|
||||
$this->fields_language_table = $fields_language_table;
|
||||
$this->fields_data_table = $fields_data_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign editable fields to template, mode can be profile (for profile change) or register (for registration)
|
||||
* Called by ucp_profile and ucp_register
|
||||
*/
|
||||
public function generate_profile_fields($mode, $lang_id)
|
||||
{
|
||||
$sql_where = '';
|
||||
switch ($mode)
|
||||
{
|
||||
case 'register':
|
||||
// If the field is required we show it on the registration page
|
||||
$sql_where .= ' AND f.field_show_on_reg = 1';
|
||||
break;
|
||||
|
||||
case 'profile':
|
||||
// Show hidden fields to moderators/admins
|
||||
if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_'))
|
||||
{
|
||||
$sql_where .= ' AND f.field_show_profile = 1';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error('Wrong profile mode specified', E_USER_ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
$sql = 'SELECT l.*, f.*
|
||||
FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f
|
||||
WHERE f.field_active = 1
|
||||
$sql_where
|
||||
AND l.lang_id = " . (int) $lang_id . '
|
||||
AND l.field_id = f.field_id
|
||||
ORDER BY f.field_order';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
// Return templated field
|
||||
$profile_field = $this->type_collection[$row['field_type']];
|
||||
$tpl_snippet = $profile_field->process_field_row('change', $row);
|
||||
|
||||
$this->template->assign_block_vars('profile_fields', array(
|
||||
'LANG_NAME' => $this->user->lang($row['lang_name']),
|
||||
'LANG_EXPLAIN' => $this->user->lang($row['lang_explain']),
|
||||
'FIELD' => $tpl_snippet,
|
||||
'FIELD_ID' => $profile_field->get_field_ident($row),
|
||||
'S_REQUIRED' => ($row['field_required']) ? true : false,
|
||||
));
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build profile cache, used for display
|
||||
*/
|
||||
protected function build_cache()
|
||||
{
|
||||
$this->profile_cache = array();
|
||||
|
||||
// Display hidden/no_view fields for admin/moderator
|
||||
$sql = 'SELECT l.*, f.*
|
||||
FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f
|
||||
WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . '
|
||||
AND f.field_active = 1 ' .
|
||||
((!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . '
|
||||
AND f.field_no_view = 0
|
||||
AND l.field_id = f.field_id
|
||||
ORDER BY f.field_order';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$this->profile_cache[$row['field_ident']] = $row;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit profile field for validation
|
||||
*/
|
||||
public function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)
|
||||
{
|
||||
$sql_where = '';
|
||||
switch ($mode)
|
||||
{
|
||||
case 'register':
|
||||
// If the field is required we show it on the registration page
|
||||
$sql_where .= ' AND f.field_show_on_reg = 1';
|
||||
break;
|
||||
|
||||
case 'profile':
|
||||
// Show hidden fields to moderators/admins
|
||||
if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_'))
|
||||
{
|
||||
$sql_where .= ' AND f.field_show_profile = 1';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error('Wrong profile mode specified', E_USER_ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
$sql = 'SELECT l.*, f.*
|
||||
FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f
|
||||
WHERE l.lang_id = ' . (int) $lang_id . "
|
||||
AND f.field_active = 1
|
||||
$sql_where
|
||||
AND l.field_id = f.field_id
|
||||
ORDER BY f.field_order";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$profile_field = $this->type_collection[$row['field_type']];
|
||||
$cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row);
|
||||
$check_value = $cp_data['pf_' . $row['field_ident']];
|
||||
|
||||
if (($cp_result = $profile_field->validate_profile_field($check_value, $row)) !== false)
|
||||
{
|
||||
// If the result is not false, it's an error message
|
||||
$cp_error[] = $cp_result;
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update profile field data directly
|
||||
*/
|
||||
public function update_profile_field_data($user_id, $cp_data)
|
||||
{
|
||||
if (!count($cp_data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'UPDATE ' . $this->fields_data_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . '
|
||||
WHERE user_id = ' . (int) $user_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
if (!$this->db->sql_affectedrows())
|
||||
{
|
||||
$cp_data = $this->build_insert_sql_array($cp_data);
|
||||
$cp_data['user_id'] = (int) $user_id;
|
||||
|
||||
$sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the template arrays in order to display the column names
|
||||
*
|
||||
* @param string $restrict_option Restrict the published fields to a certain profile field option
|
||||
* @return array Returns an array with the template variables type, name and explain for the fields to display
|
||||
*/
|
||||
public function generate_profile_fields_template_headlines($restrict_option = '')
|
||||
{
|
||||
if (!count($this->profile_cache))
|
||||
{
|
||||
$this->build_cache();
|
||||
}
|
||||
|
||||
$tpl_fields = array();
|
||||
|
||||
// Go through the fields in correct order
|
||||
foreach ($this->profile_cache as $field_ident => $field_data)
|
||||
{
|
||||
if ($restrict_option && !$field_data[$restrict_option])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$profile_field = $this->type_collection[$field_data['field_type']];
|
||||
|
||||
$tpl_fields[] = array(
|
||||
'PROFILE_FIELD_IDENT' => $field_ident,
|
||||
'PROFILE_FIELD_TYPE' => $field_data['field_type'],
|
||||
'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']),
|
||||
'PROFILE_FIELD_EXPLAIN' => $this->user->lang($field_data['lang_explain']),
|
||||
);
|
||||
}
|
||||
|
||||
$profile_cache = $this->profile_cache;
|
||||
|
||||
/**
|
||||
* Event to modify template headlines of the generated profile fields
|
||||
*
|
||||
* @event core.generate_profile_fields_template_headlines
|
||||
* @var string restrict_option Restrict the published fields to a certain profile field option
|
||||
* @var array tpl_fields Array with template data fields
|
||||
* @var array profile_cache A copy of the profile cache to make additional checks
|
||||
* @since 3.1.6-RC1
|
||||
*/
|
||||
$vars = array(
|
||||
'restrict_option',
|
||||
'tpl_fields',
|
||||
'profile_cache',
|
||||
);
|
||||
extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_headlines', compact($vars)));
|
||||
unset($profile_cache);
|
||||
|
||||
return $tpl_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 grab_profile_fields_data($user_ids = 0)
|
||||
{
|
||||
if (!is_array($user_ids))
|
||||
{
|
||||
$user_ids = array($user_ids);
|
||||
}
|
||||
|
||||
if (!count($this->profile_cache))
|
||||
{
|
||||
$this->build_cache();
|
||||
}
|
||||
|
||||
if (!count($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);
|
||||
|
||||
/**
|
||||
* Event to modify profile fields data retrieved from the database
|
||||
*
|
||||
* @event core.grab_profile_fields_data
|
||||
* @var array user_ids Single user id or an array of ids
|
||||
* @var array field_data Array with profile fields data
|
||||
* @since 3.1.0-b3
|
||||
*/
|
||||
$vars = array('user_ids', 'field_data');
|
||||
extract($this->dispatcher->trigger_event('core.grab_profile_fields_data', compact($vars)));
|
||||
|
||||
$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_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Event to modify data of the generated profile fields, before the template assignment loop
|
||||
*
|
||||
* @event core.generate_profile_fields_template_data_before
|
||||
* @var array profile_row Array with users profile field data
|
||||
* @var array tpl_fields Array with template data fields
|
||||
* @var bool use_contact_fields Should we display contact fields as such?
|
||||
* @since 3.1.0-b3
|
||||
*/
|
||||
$vars = array('profile_row', 'tpl_fields', 'use_contact_fields');
|
||||
extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars)));
|
||||
|
||||
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']);
|
||||
$value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']);
|
||||
|
||||
if ($value === null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$field_desc = $contact_url = '';
|
||||
if ($use_contact_fields && $ident_ary['data']['field_is_contact'])
|
||||
{
|
||||
$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) . '_VALUE_RAW' => $value_raw,
|
||||
'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_VALUE_RAW' => $value_raw,
|
||||
'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,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to modify template data of the generated profile fields
|
||||
*
|
||||
* @event core.generate_profile_fields_template_data
|
||||
* @var array profile_row Array with users profile field data
|
||||
* @var array tpl_fields Array with template data fields
|
||||
* @var bool use_contact_fields Should we display contact fields as such?
|
||||
* @since 3.1.0-b3
|
||||
*/
|
||||
$vars = array('profile_row', 'tpl_fields', 'use_contact_fields');
|
||||
extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data', compact($vars)));
|
||||
|
||||
return $tpl_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Array for user insertion into custom profile fields table
|
||||
*/
|
||||
public function build_insert_sql_array($cp_data)
|
||||
{
|
||||
$sql_not_in = array();
|
||||
foreach ($cp_data as $key => $null)
|
||||
{
|
||||
$sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key;
|
||||
}
|
||||
|
||||
$sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value
|
||||
FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f
|
||||
WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . '
|
||||
' . ((count($sql_not_in)) ? ' AND ' . $this->db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . '
|
||||
AND l.field_id = f.field_id';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$profile_field = $this->type_collection[$row['field_type']];
|
||||
$cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $cp_data;
|
||||
}
|
||||
}
|
206
msd2/phpBB3/phpbb/profilefields/type/type_base.php
Normal file
206
msd2/phpBB3/phpbb/profilefields/type/type_base.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
abstract class type_base implements type_interface
|
||||
{
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->user->lang('FIELD_' . strtoupper($this->get_name_short()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_service_name()
|
||||
{
|
||||
return 'profilefields.type.' . $this->get_name_short();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_template_filename()
|
||||
{
|
||||
return 'profilefields/' . $this->get_name_short() . '.html';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_field_ident($field_data)
|
||||
{
|
||||
return 'pf_' . $field_data['field_ident'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_field_name($field_name)
|
||||
{
|
||||
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}
|
||||
*/
|
||||
public function get_language_options_input($field_data)
|
||||
{
|
||||
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
|
||||
$field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true);
|
||||
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true);
|
||||
$field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true);
|
||||
|
||||
return $field_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_options_form(&$exclude_options, &$visibility_options)
|
||||
{
|
||||
return $this->request->variable('lang_options', '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_options_on_submit($error, $field_data)
|
||||
{
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
|
||||
{
|
||||
if ($step == 3 && ($field_data[$key] || $action != 'edit') && $key == 'l_lang_options' && is_array($field_data[$key]))
|
||||
{
|
||||
foreach ($field_data[$key] as $lang_id => $options)
|
||||
{
|
||||
$field_data[$key][$lang_id] = is_array($options) ? $options : explode("\n", $options);
|
||||
}
|
||||
|
||||
return $current_value;
|
||||
}
|
||||
|
||||
return $current_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_hidden_fields($step, $key, $action, &$field_data)
|
||||
{
|
||||
if (!$this->request->is_set($key))
|
||||
{
|
||||
// Do not set this variable, we will use the default value
|
||||
return null;
|
||||
}
|
||||
else if ($key == 'field_ident' && isset($field_data[$key]))
|
||||
{
|
||||
return $field_data[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
$default_value = '';
|
||||
$lang_fields = array(
|
||||
'l_lang_name',
|
||||
'l_lang_explain',
|
||||
'l_lang_default_value',
|
||||
'l_lang_options',
|
||||
);
|
||||
|
||||
if (in_array($key, $lang_fields))
|
||||
{
|
||||
$default_value = array(0 => '');
|
||||
}
|
||||
return $this->request->variable($key, $default_value, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function display_options(&$template_vars, &$field_data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return templated value/field. Possible values for $mode are:
|
||||
* change == user is able to set/enter profile values; preview == just show the value
|
||||
*/
|
||||
public function process_field_row($mode, $profile_row)
|
||||
{
|
||||
$preview_options = ($mode == 'preview') ? $profile_row['lang_options'] : false;
|
||||
|
||||
// set template filename
|
||||
$this->template->set_filenames(array(
|
||||
'cp_body' => $this->get_template_filename(),
|
||||
));
|
||||
|
||||
// empty previously filled blockvars
|
||||
$this->template->destroy_block_vars($this->get_name_short());
|
||||
|
||||
// Assign template variables
|
||||
$this->generate_field($profile_row, $preview_options);
|
||||
|
||||
return $this->template->assign_display('cp_body');
|
||||
}
|
||||
}
|
415
msd2/phpBB3/phpbb/profilefields/type/type_bool.php
Normal file
415
msd2/phpBB3/phpbb/profilefields/type/type_bool.php
Normal file
@ -0,0 +1,415 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
class type_bool extends type_base
|
||||
{
|
||||
/**
|
||||
* Profile fields language helper
|
||||
* @var \phpbb\profilefields\lang_helper
|
||||
*/
|
||||
protected $lang_helper;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->lang_helper = $lang_helper;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name_short()
|
||||
{
|
||||
return 'bool';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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' => $this->get_service_name(),
|
||||
'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->process_field_row('preview', $profile_row)),
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_option_values()
|
||||
{
|
||||
return array(
|
||||
'field_length' => 1,
|
||||
'field_minlen' => 0,
|
||||
'field_maxlen' => 0,
|
||||
'field_validation' => '',
|
||||
'field_novalue' => 0,
|
||||
'field_default_value' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_field_value($field_data)
|
||||
{
|
||||
return $field_data['field_default_value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_field($profile_row)
|
||||
{
|
||||
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||
|
||||
// Checkbox
|
||||
if ($profile_row['field_length'] == 2)
|
||||
{
|
||||
return ($this->request->is_set($var_name)) ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data)
|
||||
{
|
||||
$field_value = (bool) $field_value;
|
||||
|
||||
if (!$field_value && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
$field_id = $field_data['field_id'];
|
||||
$lang_id = $field_data['lang_id'];
|
||||
|
||||
if (!$this->lang_helper->is_set($field_id, $lang_id))
|
||||
{
|
||||
$this->lang_helper->load_option_lang($lang_id);
|
||||
}
|
||||
|
||||
if (!$field_value && $field_data['field_show_novalue'])
|
||||
{
|
||||
$field_value = $field_data['field_default_value'];
|
||||
}
|
||||
|
||||
if ($field_data['field_length'] == 1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->lang_helper->is_set($field_id, $lang_id, $field_value + 1) ? $this->lang_helper->get($field_id, $lang_id, $field_value + 1) : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value_raw($field_value, $field_data)
|
||||
{
|
||||
if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$field_value && $field_data['field_show_novalue'])
|
||||
{
|
||||
$field_value = $field_data['field_novalue'];
|
||||
}
|
||||
|
||||
return $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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'];
|
||||
$field_ident = $profile_row['field_ident'];
|
||||
$default_value = $profile_row['field_default_value'];
|
||||
|
||||
// checkbox - set the value to "true" if it has been set to 1
|
||||
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_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$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;
|
||||
$this->template->assign_block_vars('bool', array_change_key_case($profile_row, CASE_UPPER));
|
||||
|
||||
if ($profile_row['field_length'] == 1)
|
||||
{
|
||||
if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1))
|
||||
{
|
||||
if ($preview_options)
|
||||
{
|
||||
$this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->lang_helper->load_option_lang($profile_row['lang_id']);
|
||||
}
|
||||
}
|
||||
|
||||
$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(
|
||||
'OPTION_ID' => $option_id,
|
||||
'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '',
|
||||
'VALUE' => $option_value,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_field_ident($field_data)
|
||||
{
|
||||
return ($field_data['field_length'] == '1') ? '' : 'pf_' . $field_data['field_ident'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_database_column_type()
|
||||
{
|
||||
return 'TINT:2';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_language_options($field_data)
|
||||
{
|
||||
$options = array(
|
||||
'lang_name' => 'string',
|
||||
'lang_options' => 'two_options',
|
||||
);
|
||||
|
||||
if ($field_data['lang_explain'])
|
||||
{
|
||||
$options['lang_explain'] = 'text';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_language_options_input($field_data)
|
||||
{
|
||||
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
|
||||
$field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true);
|
||||
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true);
|
||||
|
||||
/**
|
||||
* @todo check if this line is correct...
|
||||
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => array('')), true);
|
||||
*/
|
||||
$field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => array('')), true);
|
||||
|
||||
return $field_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_options_form(&$exclude_options, &$visibility_options)
|
||||
{
|
||||
$exclude_options[1][] = 'lang_options';
|
||||
|
||||
return $this->request->variable('lang_options', array(''), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_options_on_submit($error, $field_data)
|
||||
{
|
||||
if (empty($field_data['lang_options'][0]) || empty($field_data['lang_options'][1]))
|
||||
{
|
||||
$error[] = $this->user->lang['NO_FIELD_ENTRIES'];
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
|
||||
{
|
||||
if ($step == 2 && $key == 'field_default_value')
|
||||
{
|
||||
// 'field_length' == 1 defines radio buttons. Possible values are 1 or 2 only.
|
||||
// 'field_length' == 2 defines checkbox. Possible values are 0 or 1 only.
|
||||
// If we switch the type on step 2, we have to adjust field value.
|
||||
// 1 is a common value for the checkbox and radio buttons.
|
||||
|
||||
// Adjust unchecked checkbox value.
|
||||
// If we return or save settings from 2nd/3rd page
|
||||
// and the checkbox is unchecked, set the value to 0.
|
||||
if ($this->request->is_set('step') && !$this->request->is_set($key))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If we switch to the checkbox type but former radio buttons value was 2,
|
||||
// which is not the case for the checkbox, set it to 0 (unchecked).
|
||||
if ($field_data['field_length'] == 2 && $current_value == 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// If we switch to the radio buttons but the former checkbox value was 0,
|
||||
// which is not the case for the radio buttons, set it to 0.
|
||||
else if ($field_data['field_length'] == 1 && $current_value == 0)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
if ($key == 'l_lang_options' && $this->request->is_set($key))
|
||||
{
|
||||
$field_data[$key] = $this->request->variable($key, array(0 => array('')), true);
|
||||
|
||||
return $current_value;
|
||||
}
|
||||
|
||||
return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_hidden_fields($step, $key, $action, &$field_data)
|
||||
{
|
||||
if ($key == 'field_default_value')
|
||||
{
|
||||
$field_length = $this->request->variable('field_length', 0);
|
||||
|
||||
// Do a simple is set check if using checkbox.
|
||||
if ($field_length == 2)
|
||||
{
|
||||
return $this->request->is_set($key);
|
||||
}
|
||||
return $this->request->variable($key, $field_data[$key], true);
|
||||
}
|
||||
|
||||
$default_lang_options = array(
|
||||
'l_lang_options' => array(0 => array('')),
|
||||
'lang_options' => array(0 => ''),
|
||||
);
|
||||
|
||||
if (isset($default_lang_options[$key]) && $this->request->is_set($key))
|
||||
{
|
||||
return $this->request->variable($key, $default_lang_options[$key], true);
|
||||
}
|
||||
|
||||
return parent::prepare_hidden_fields($step, $key, $action, $field_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function display_options(&$template_vars, &$field_data)
|
||||
{
|
||||
// Initialize these array elements if we are creating a new field
|
||||
if (!count($field_data['lang_options']))
|
||||
{
|
||||
// No options have been defined for a boolean field.
|
||||
$field_data['lang_options'][0] = '';
|
||||
$field_data['lang_options'][1] = '';
|
||||
}
|
||||
|
||||
$template_vars = array_merge($template_vars, array(
|
||||
'S_BOOL' => true,
|
||||
'L_LANG_OPTIONS_EXPLAIN' => $this->user->lang['BOOL_ENTRIES_EXPLAIN'],
|
||||
'FIRST_LANG_OPTION' => $field_data['lang_options'][0],
|
||||
'SECOND_LANG_OPTION' => $field_data['lang_options'][1],
|
||||
));
|
||||
}
|
||||
}
|
374
msd2/phpBB3/phpbb/profilefields/type/type_date.php
Normal file
374
msd2/phpBB3/phpbb/profilefields/type/type_date.php
Normal file
@ -0,0 +1,374 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
class type_date extends type_base
|
||||
{
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name_short()
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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' => $this->get_service_name(),
|
||||
'field_length' => $field_data['field_length'],
|
||||
'lang_options' => $field_data['lang_options'],
|
||||
);
|
||||
|
||||
$always_now = $this->request->variable('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->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_option_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',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_field_value($field_data)
|
||||
{
|
||||
if ($field_data['field_default_value'] == 'now')
|
||||
{
|
||||
$now = getdate();
|
||||
$field_data['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
||||
}
|
||||
|
||||
return $field_data['field_default_value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_field($profile_row)
|
||||
{
|
||||
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||
|
||||
if (!$this->request->is_set($var_name . '_day'))
|
||||
{
|
||||
if ($profile_row['field_default_value'] == 'now')
|
||||
{
|
||||
$now = getdate();
|
||||
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
||||
}
|
||||
list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$day = $this->request->variable($var_name . '_day', 0);
|
||||
$month = $this->request->variable($var_name . '_month', 0);
|
||||
$year = $this->request->variable($var_name . '_year', 0);
|
||||
}
|
||||
|
||||
return sprintf('%2d-%2d-%4d', $day, $month, $year);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data)
|
||||
{
|
||||
$field_validate = explode('-', $field_value);
|
||||
|
||||
$day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0;
|
||||
$month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0;
|
||||
$year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0;
|
||||
|
||||
if ((!$day || !$month || !$year) && !$field_data['field_required'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((!$day || !$month || !$year) && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
|
||||
{
|
||||
return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if (checkdate($month, $day, $year) === false)
|
||||
{
|
||||
return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
$date = explode('-', $field_value);
|
||||
$day = (isset($date[0])) ? (int) $date[0] : 0;
|
||||
$month = (isset($date[1])) ? (int) $date[1] : 0;
|
||||
$year = (isset($date[2])) ? (int) $date[2] : 0;
|
||||
|
||||
if (!$day && !$month && !$year && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if ($day && $month && $year)
|
||||
{
|
||||
// Date should display as the same date for every user regardless of timezone
|
||||
return $this->user->create_datetime()
|
||||
->setDate($year, $month, $day)
|
||||
->setTime(0, 0, 0)
|
||||
->format($this->user->lang['DATE_FORMAT'], true);
|
||||
}
|
||||
|
||||
return $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value_raw($field_value, $field_data)
|
||||
{
|
||||
if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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'];
|
||||
$field_ident = $profile_row['field_ident'];
|
||||
|
||||
$now = getdate();
|
||||
|
||||
if (!$this->request->is_set($profile_row['field_ident'] . '_day'))
|
||||
{
|
||||
if ($profile_row['field_default_value'] == 'now')
|
||||
{
|
||||
$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[$field_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident]));
|
||||
}
|
||||
else
|
||||
{
|
||||
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']);
|
||||
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident]));
|
||||
}
|
||||
else
|
||||
{
|
||||
$day = $this->request->variable($profile_row['field_ident'] . '_day', 0);
|
||||
$month = $this->request->variable($profile_row['field_ident'] . '_month', 0);
|
||||
$year = $this->request->variable($profile_row['field_ident'] . '_year', 0);
|
||||
}
|
||||
}
|
||||
|
||||
$profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>';
|
||||
for ($i = 1; $i < 32; $i++)
|
||||
{
|
||||
$profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>";
|
||||
}
|
||||
|
||||
$profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>';
|
||||
for ($i = 1; $i < 13; $i++)
|
||||
{
|
||||
$profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>";
|
||||
}
|
||||
|
||||
$profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>';
|
||||
for ($i = 1901; $i <= $now['year'] + 50; $i++)
|
||||
{
|
||||
$profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";
|
||||
}
|
||||
|
||||
$profile_row['field_value'] = 0;
|
||||
$this->template->assign_block_vars('date', array_change_key_case($profile_row, CASE_UPPER));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_field_ident($field_data)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_database_column_type()
|
||||
{
|
||||
return 'VCHAR:10';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_language_options($field_data)
|
||||
{
|
||||
$options = array(
|
||||
'lang_name' => 'string',
|
||||
);
|
||||
|
||||
if ($field_data['lang_explain'])
|
||||
{
|
||||
$options['lang_explain'] = 'text';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
|
||||
{
|
||||
if ($step == 2 && $key == 'field_default_value')
|
||||
{
|
||||
$always_now = $this->request->variable('always_now', -1);
|
||||
|
||||
if ($always_now == 1 || ($always_now === -1 && $current_value == 'now'))
|
||||
{
|
||||
$now = getdate();
|
||||
|
||||
$field_data['field_default_value_day'] = $now['mday'];
|
||||
$field_data['field_default_value_month'] = $now['mon'];
|
||||
$field_data['field_default_value_year'] = $now['year'];
|
||||
$current_value = 'now';
|
||||
$this->request->overwrite('field_default_value', $current_value, \phpbb\request\request_interface::POST);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->request->is_set('field_default_value_day'))
|
||||
{
|
||||
$field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0);
|
||||
$field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0);
|
||||
$field_data['field_default_value_year'] = $this->request->variable('field_default_value_year', 0);
|
||||
$current_value = sprintf('%2d-%2d-%4d', $field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']);
|
||||
$this->request->overwrite('field_default_value', $current_value, \phpbb\request\request_interface::POST);
|
||||
}
|
||||
else
|
||||
{
|
||||
list($field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']) = explode('-', $current_value);
|
||||
}
|
||||
}
|
||||
|
||||
return $current_value;
|
||||
}
|
||||
|
||||
return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_hidden_fields($step, $key, $action, &$field_data)
|
||||
{
|
||||
if ($key == 'field_default_value')
|
||||
{
|
||||
$always_now = $this->request->variable('always_now', 0);
|
||||
|
||||
if ($always_now)
|
||||
{
|
||||
return 'now';
|
||||
}
|
||||
else if ($this->request->is_set('field_default_value_day'))
|
||||
{
|
||||
$field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0);
|
||||
$field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0);
|
||||
$field_data['field_default_value_year'] = $this->request->variable('field_default_value_year', 0);
|
||||
return sprintf('%2d-%2d-%4d', $field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::prepare_hidden_fields($step, $key, $action, $field_data);
|
||||
}
|
||||
}
|
325
msd2/phpBB3/phpbb/profilefields/type/type_dropdown.php
Normal file
325
msd2/phpBB3/phpbb/profilefields/type/type_dropdown.php
Normal file
@ -0,0 +1,325 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
class type_dropdown extends type_base
|
||||
{
|
||||
/**
|
||||
* Profile fields language helper
|
||||
* @var \phpbb\profilefields\lang_helper
|
||||
*/
|
||||
protected $lang_helper;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->lang_helper = $lang_helper;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name_short()
|
||||
{
|
||||
return 'dropdown';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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' => $this->get_service_name(),
|
||||
'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->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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_option_values()
|
||||
{
|
||||
return array(
|
||||
'field_length' => 0,
|
||||
'field_minlen' => 0,
|
||||
'field_maxlen' => 5,
|
||||
'field_validation' => '',
|
||||
'field_novalue' => 0,
|
||||
'field_default_value' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_field_value($field_data)
|
||||
{
|
||||
return $field_data['field_default_value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_field($profile_row)
|
||||
{
|
||||
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||
return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data)
|
||||
{
|
||||
$field_value = (int) $field_value;
|
||||
|
||||
// retrieve option lang data if necessary
|
||||
if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1))
|
||||
{
|
||||
$this->lang_helper->load_option_lang($field_data['lang_id']);
|
||||
}
|
||||
|
||||
if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value))
|
||||
{
|
||||
return $this->user->lang('FIELD_INVALID_VALUE', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
$field_id = $field_data['field_id'];
|
||||
$lang_id = $field_data['lang_id'];
|
||||
if (!$this->lang_helper->is_set($field_id, $lang_id))
|
||||
{
|
||||
$this->lang_helper->load_option_lang($lang_id);
|
||||
}
|
||||
|
||||
if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$field_value = (int) $field_value;
|
||||
|
||||
// User not having a value assigned
|
||||
if (!$this->lang_helper->is_set($field_id, $lang_id, $field_value))
|
||||
{
|
||||
if ($field_data['field_show_novalue'])
|
||||
{
|
||||
$field_value = $field_data['field_novalue'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->lang_helper->get($field_id, $lang_id, $field_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value_raw($field_value, $field_data)
|
||||
{
|
||||
if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$field_value && $field_data['field_show_novalue'])
|
||||
{
|
||||
$field_value = $field_data['field_novalue'];
|
||||
}
|
||||
|
||||
return $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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'];
|
||||
$field_ident = $profile_row['field_ident'];
|
||||
$default_value = $profile_row['field_default_value'];
|
||||
|
||||
$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 (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1))
|
||||
{
|
||||
if ($preview_options)
|
||||
{
|
||||
$this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->lang_helper->load_option_lang($profile_row['lang_id']);
|
||||
}
|
||||
}
|
||||
|
||||
$profile_row['field_value'] = (int) $value;
|
||||
$this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER));
|
||||
|
||||
$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(
|
||||
'OPTION_ID' => $option_id,
|
||||
'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '',
|
||||
'VALUE' => $option_value,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_database_column_type()
|
||||
{
|
||||
return 'UINT';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_language_options($field_data)
|
||||
{
|
||||
$options = array(
|
||||
'lang_name' => 'string',
|
||||
'lang_options' => 'optionfield',
|
||||
);
|
||||
|
||||
if ($field_data['lang_explain'])
|
||||
{
|
||||
$options['lang_explain'] = 'text';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_options_form(&$exclude_options, &$visibility_options)
|
||||
{
|
||||
$exclude_options[1][] = 'lang_options';
|
||||
|
||||
return $this->request->variable('lang_options', '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_options_on_submit($error, $field_data)
|
||||
{
|
||||
if (!count($field_data['lang_options']))
|
||||
{
|
||||
$error[] = $this->user->lang['NO_FIELD_ENTRIES'];
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
|
||||
{
|
||||
if ($step == 2 && $key == 'field_maxlen')
|
||||
{
|
||||
// Get the number of options if this key is 'field_maxlen'
|
||||
return count(explode("\n", $this->request->variable('lang_options', '', true)));
|
||||
}
|
||||
|
||||
return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function display_options(&$template_vars, &$field_data)
|
||||
{
|
||||
// Initialize these array elements if we are creating a new field
|
||||
if (!count($field_data['lang_options']))
|
||||
{
|
||||
// No options have been defined for the dropdown menu
|
||||
$field_data['lang_options'] = array();
|
||||
}
|
||||
|
||||
$template_vars = array_merge($template_vars, array(
|
||||
'S_DROPDOWN' => true,
|
||||
'L_LANG_OPTIONS_EXPLAIN' => $this->user->lang['DROPDOWN_ENTRIES_EXPLAIN'],
|
||||
'LANG_OPTIONS' => implode("\n", $field_data['lang_options']),
|
||||
));
|
||||
}
|
||||
}
|
66
msd2/phpBB3/phpbb/profilefields/type/type_googleplus.php
Normal file
66
msd2/phpBB3/phpbb/profilefields/type/type_googleplus.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
class type_googleplus extends type_string
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->user->lang('FIELD_GOOGLEPLUS');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_service_name()
|
||||
{
|
||||
return 'profilefields.type.googleplus';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_option_values()
|
||||
{
|
||||
return array(
|
||||
'field_length' => 20,
|
||||
'field_minlen' => 3,
|
||||
'field_maxlen' => 255,
|
||||
'field_validation' => '(?:(?!\.{2,})([^<>=+]))+',
|
||||
'field_novalue' => '',
|
||||
'field_default_value' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_contact_value($field_value, $field_data)
|
||||
{
|
||||
if (!$field_value && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_numeric($field_value))
|
||||
{
|
||||
$field_value = '+' . $field_value;
|
||||
}
|
||||
|
||||
return $field_value;
|
||||
}
|
||||
}
|
249
msd2/phpBB3/phpbb/profilefields/type/type_int.php
Normal file
249
msd2/phpBB3/phpbb/profilefields/type/type_int.php
Normal file
@ -0,0 +1,249 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
class type_int extends type_base
|
||||
{
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name_short()
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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" 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" 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" value="' . $field_data['field_maxlen'] . '" />'),
|
||||
3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="number" name="field_default_value" value="' . $field_data['field_default_value'] . '" />'),
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_option_values()
|
||||
{
|
||||
return array(
|
||||
'field_length' => 5,
|
||||
'field_minlen' => 0,
|
||||
'field_maxlen' => 100,
|
||||
'field_validation' => '',
|
||||
'field_novalue' => 0,
|
||||
'field_default_value' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_field_value($field_data)
|
||||
{
|
||||
if ($field_data['field_default_value'] === '')
|
||||
{
|
||||
// We cannot insert an empty string into an integer column.
|
||||
return null;
|
||||
}
|
||||
|
||||
return $field_data['field_default_value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_field($profile_row)
|
||||
{
|
||||
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||
if ($this->request->is_set($var_name) && $this->request->variable($var_name, '') === '')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data)
|
||||
{
|
||||
if (trim($field_value) === '' && !$field_data['field_required'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$field_value = (int) $field_value;
|
||||
|
||||
if ($field_value < $field_data['field_minlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_SMALL', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
else if ($field_value > $field_data['field_maxlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_LARGE', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (int) $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value_raw($field_value, $field_data)
|
||||
{
|
||||
if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (int) $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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'];
|
||||
$field_ident = $profile_row['field_ident'];
|
||||
$default_value = $profile_row['field_default_value'];
|
||||
|
||||
if ($this->request->is_set($field_ident))
|
||||
{
|
||||
$value = ($this->request->variable($field_ident, '') === '') ? null : $this->request->variable($field_ident, $default_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($preview_options === false && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident]))
|
||||
{
|
||||
$value = null;
|
||||
}
|
||||
else if (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false)
|
||||
{
|
||||
$value = $default_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = $this->user->profile_fields[$field_ident];
|
||||
}
|
||||
}
|
||||
|
||||
$profile_row['field_value'] = (is_null($value) || $value === '') ? '' : (int) $value;
|
||||
|
||||
$this->template->assign_block_vars('int', array_change_key_case($profile_row, CASE_UPPER));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_field_ident($field_data)
|
||||
{
|
||||
return 'pf_' . $field_data['field_ident'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_database_column_type()
|
||||
{
|
||||
return 'BINT';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_language_options($field_data)
|
||||
{
|
||||
$options = array(
|
||||
'lang_name' => 'string',
|
||||
);
|
||||
|
||||
if ($field_data['lang_explain'])
|
||||
{
|
||||
$options['lang_explain'] = 'text';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
|
||||
{
|
||||
if ($step == 2 && $key == 'field_default_value')
|
||||
{
|
||||
// Permit an empty string
|
||||
if ($action == 'create' && $this->request->variable('field_default_value', '') === '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
|
||||
}
|
||||
}
|
226
msd2/phpBB3/phpbb/profilefields/type/type_interface.php
Normal file
226
msd2/phpBB3/phpbb/profilefields/type/type_interface.php
Normal file
@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
interface type_interface
|
||||
{
|
||||
/**
|
||||
* Get the translated name of the type
|
||||
*
|
||||
* @return string Translated name of the field type
|
||||
*/
|
||||
public function get_name();
|
||||
|
||||
/**
|
||||
* Get the short name of the type, used for error messages and template loops
|
||||
*
|
||||
* @return string lowercase version of the fields type
|
||||
*/
|
||||
public function get_name_short();
|
||||
|
||||
/**
|
||||
* Get the name of service representing the type
|
||||
*
|
||||
* @return string lowercase version of the fields type
|
||||
*/
|
||||
public function get_service_name();
|
||||
|
||||
/**
|
||||
* Get the name of template file for this type
|
||||
*
|
||||
* @return string Returns the name of the template file
|
||||
*/
|
||||
public function get_template_filename();
|
||||
|
||||
/**
|
||||
* 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 the options of this type
|
||||
*
|
||||
* @return array with values like default field size and more
|
||||
*/
|
||||
public function get_default_option_values();
|
||||
|
||||
/**
|
||||
* Get default value for this type
|
||||
*
|
||||
* @param array $field_data Array with data for this field
|
||||
* @return mixed default value for new users when no value is given
|
||||
*/
|
||||
public function get_default_field_value($field_data);
|
||||
|
||||
/**
|
||||
* Get profile field value on submit
|
||||
*
|
||||
* @param array $profile_row Array with data for this field
|
||||
* @return mixed Submitted value of the profile field
|
||||
*/
|
||||
public function get_profile_field($profile_row);
|
||||
|
||||
/**
|
||||
* Validate entered profile field data
|
||||
*
|
||||
* @param mixed $field_value Field value to validate
|
||||
* @param array $field_data Array with requirements of the field
|
||||
* @return mixed String with the error message
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data);
|
||||
|
||||
/**
|
||||
* Get Profile Value for display
|
||||
*
|
||||
* @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_value($field_value, $field_data);
|
||||
|
||||
/**
|
||||
* Get Profile Value ID for display (the raw, unprocessed user data)
|
||||
*
|
||||
* @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 ID to display
|
||||
*/
|
||||
public function get_profile_value_raw($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
|
||||
* @param mixed $preview_options When previewing we use different data
|
||||
* @return null
|
||||
*/
|
||||
public function generate_field($profile_row, $preview_options = false);
|
||||
|
||||
/**
|
||||
* Get the ident of the field
|
||||
*
|
||||
* Some types are multivalue, we can't give them a field_id
|
||||
* as we would not know which to pick.
|
||||
*
|
||||
* @param array $field_data Array with data for this field
|
||||
* @return string ident of the field
|
||||
*/
|
||||
public function get_field_ident($field_data);
|
||||
|
||||
/**
|
||||
* Get the localized name of the field
|
||||
*
|
||||
* @param string $field_name Unlocalized name of this field
|
||||
* @return string Localized name of the field
|
||||
*/
|
||||
public function get_field_name($field_name);
|
||||
|
||||
/**
|
||||
* Get the column type for the database
|
||||
*
|
||||
* @return string Returns the database column type
|
||||
*/
|
||||
public function get_database_column_type();
|
||||
|
||||
/**
|
||||
* Get the options we need to display for the language input fields in the ACP
|
||||
*
|
||||
* @param array $field_data Array with data for this field
|
||||
* @return array Returns the language options we need to generate
|
||||
*/
|
||||
public function get_language_options($field_data);
|
||||
|
||||
/**
|
||||
* Get the input for the supplied language options
|
||||
*
|
||||
* @param array $field_data Array with data for this field
|
||||
* @return array Returns the language options we need to generate
|
||||
*/
|
||||
public function get_language_options_input($field_data);
|
||||
|
||||
/**
|
||||
* Allows exclusion of options in single steps of the creation process
|
||||
*
|
||||
* @param array $exclude_options Array with options that should be excluded in the steps
|
||||
* @param array $visibility_options Array with options responsible for the fields visibility
|
||||
* @return mixed Returns the provided language options
|
||||
*/
|
||||
public function prepare_options_form(&$exclude_options, &$visibility_options);
|
||||
|
||||
/**
|
||||
* Allows exclusion of options in single steps of the creation process
|
||||
*
|
||||
* @param array $error Array with error messages
|
||||
* @param array $field_data Array with data for this field
|
||||
* @return array Array with error messages
|
||||
*/
|
||||
public function validate_options_on_submit($error, $field_data);
|
||||
|
||||
/**
|
||||
* Allows manipulating the intended variables if needed
|
||||
*
|
||||
* @param string $key Name of the option
|
||||
* @param string $action Currently performed action (create|edit)
|
||||
* @param mixed $current_value Currently value of the option
|
||||
* @param array $field_data Array with data for this field
|
||||
* @param int $step Step on which the option is excluded
|
||||
* @return mixed Final value of the option
|
||||
*/
|
||||
public function get_excluded_options($key, $action, $current_value, &$field_data, $step);
|
||||
|
||||
/**
|
||||
* Allows manipulating the intended variables if needed
|
||||
*
|
||||
* @param int $step Step on which the option is hidden
|
||||
* @param string $key Name of the option
|
||||
* @param string $action Currently performed action (create|edit)
|
||||
* @param array $field_data Array with data for this field
|
||||
* @return mixed Final value of the option
|
||||
*/
|
||||
public function prepare_hidden_fields($step, $key, $action, &$field_data);
|
||||
|
||||
/**
|
||||
* Allows assigning of additional template variables
|
||||
*
|
||||
* @param array $template_vars Template variables we are going to assign
|
||||
* @param array $field_data Array with data for this field
|
||||
* @return null
|
||||
*/
|
||||
public function display_options(&$template_vars, &$field_data);
|
||||
|
||||
/**
|
||||
* Return templated value/field. Possible values for $mode are:
|
||||
* change == user is able to set/enter profile values; preview == just show the value
|
||||
*
|
||||
* @param string $mode Mode for displaying the field (preview|change)
|
||||
* @param array $profile_row Array with data for this field
|
||||
* @return null
|
||||
*/
|
||||
public function process_field_row($mode, $profile_row);
|
||||
}
|
159
msd2/phpBB3/phpbb/profilefields/type/type_string.php
Normal file
159
msd2/phpBB3/phpbb/profilefields/type/type_string.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
class type_string extends type_string_common
|
||||
{
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name_short()
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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" value="' . $field_data['field_length'] . '" />'),
|
||||
1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_minlen" value="' . $field_data['field_minlen'] . '" />'),
|
||||
2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_maxlen" 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_option_values()
|
||||
{
|
||||
return array(
|
||||
'field_length' => 10,
|
||||
'field_minlen' => 0,
|
||||
'field_maxlen' => 20,
|
||||
'field_validation' => '.*',
|
||||
'field_novalue' => '',
|
||||
'field_default_value' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_field($profile_row)
|
||||
{
|
||||
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||
return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data)
|
||||
{
|
||||
return $this->validate_string_profile_field('string', $field_value, $field_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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'];
|
||||
$field_ident = $profile_row['field_ident'];
|
||||
$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($this->get_name_short(), array_change_key_case($profile_row, CASE_UPPER));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_database_column_type()
|
||||
{
|
||||
return 'VCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_language_options($field_data)
|
||||
{
|
||||
$options = array(
|
||||
'lang_name' => 'string',
|
||||
);
|
||||
|
||||
if ($field_data['lang_explain'])
|
||||
{
|
||||
$options['lang_explain'] = 'text';
|
||||
}
|
||||
|
||||
if (strlen($field_data['lang_default_value']))
|
||||
{
|
||||
$options['lang_default_value'] = 'string';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function display_options(&$template_vars, &$field_data)
|
||||
{
|
||||
$template_vars = array_merge($template_vars, array(
|
||||
'S_STRING' => true,
|
||||
'L_DEFAULT_VALUE_EXPLAIN' => $this->user->lang['STRING_DEFAULT_VALUE_EXPLAIN'],
|
||||
'LANG_DEFAULT_VALUE' => $field_data['lang_default_value'],
|
||||
));
|
||||
}
|
||||
}
|
147
msd2/phpBB3/phpbb/profilefields/type/type_string_common.php
Normal file
147
msd2/phpBB3/phpbb/profilefields/type/type_string_common.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
abstract class type_string_common extends type_base
|
||||
{
|
||||
protected $validation_options = array(
|
||||
'CHARS_ANY' => '.*',
|
||||
'NUMBERS_ONLY' => '[0-9]+',
|
||||
'ALPHA_ONLY' => '[a-zA-Z0-9]+',
|
||||
'ALPHA_UNDERSCORE' => '[\w]+',
|
||||
'ALPHA_DOTS' => '[a-zA-Z0-9.]+',
|
||||
'ALPHA_SPACERS' => '[\w\x20+\-\[\]]+',
|
||||
'ALPHA_PUNCTUATION' => '[a-zA-Z][\w\.,\-]+',
|
||||
'LETTER_NUM_ONLY' => '[\p{Lu}\p{Ll}0-9]+',
|
||||
'LETTER_NUM_UNDERSCORE' => '[\p{Lu}\p{Ll}0-9_]+',
|
||||
'LETTER_NUM_DOTS' => '[\p{Lu}\p{Ll}0-9.]+',
|
||||
'LETTER_NUM_SPACERS' => '[\p{Lu}\p{Ll}0-9\x20_+\-\[\]]+',
|
||||
'LETTER_NUM_PUNCTUATION' => '[\p{Lu}\p{Ll}][\p{Lu}\p{Ll}0-9.,\-_]+',
|
||||
);
|
||||
|
||||
/**
|
||||
* Return possible validation options
|
||||
*/
|
||||
public function validate_options($field_data)
|
||||
{
|
||||
$validate_options = '';
|
||||
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>';
|
||||
}
|
||||
|
||||
return $validate_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_default_field_value($field_data)
|
||||
{
|
||||
return $field_data['lang_default_value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate entered profile field data
|
||||
*
|
||||
* @param string $field_type Field type (string or text)
|
||||
* @param mixed $field_value Field value to validate
|
||||
* @param array $field_data Array with requirements of the field
|
||||
* @return mixed String with key of the error language string, false otherwise
|
||||
*/
|
||||
public function validate_string_profile_field($field_type, &$field_value, $field_data)
|
||||
{
|
||||
if (trim($field_value) === '' && !$field_data['field_required'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (trim($field_value) === '' && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_SHORT', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
else if ($field_data['field_maxlen'] && utf8_strlen(html_entity_decode($field_value)) > $field_data['field_maxlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_LONG', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
|
||||
{
|
||||
$field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value);
|
||||
if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#iu', $field_validate))
|
||||
{
|
||||
$validation = array_search($field_data['field_validation'], $this->validation_options);
|
||||
if ($validation)
|
||||
{
|
||||
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']));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$field_value = make_clickable($field_value);
|
||||
$field_value = censor_text($field_value);
|
||||
$field_value = bbcode_nl2br($field_value);
|
||||
return $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value_raw($field_value, $field_data)
|
||||
{
|
||||
if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $field_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_contact_value($field_value, $field_data)
|
||||
{
|
||||
return $this->get_profile_value_raw($field_value, $field_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_options_form(&$exclude_options, &$visibility_options)
|
||||
{
|
||||
$exclude_options[1][] = 'lang_default_value';
|
||||
|
||||
return $this->request->variable('lang_options', '', true);
|
||||
}
|
||||
}
|
204
msd2/phpBB3/phpbb/profilefields/type/type_text.php
Normal file
204
msd2/phpBB3/phpbb/profilefields/type/type_text.php
Normal file
@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\profilefields\type;
|
||||
|
||||
class type_text extends type_string_common
|
||||
{
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var \phpbb\template\template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
*/
|
||||
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name_short()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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" value="' . $field_data['rows'] . '" /> ' . $this->user->lang['ROWS'] . '</dd><dd><input type="number" min="0" max="99999" name="columns" 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" 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" 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_option_values()
|
||||
{
|
||||
return array(
|
||||
'field_length' => '5|80',
|
||||
'field_minlen' => 0,
|
||||
'field_maxlen' => 1000,
|
||||
'field_validation' => '.*',
|
||||
'field_novalue' => '',
|
||||
'field_default_value' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_field($profile_row)
|
||||
{
|
||||
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||
return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data)
|
||||
{
|
||||
return $this->validate_string_profile_field('text', $field_value, $field_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate_field($profile_row, $preview_options = false)
|
||||
{
|
||||
$field_length = explode('|', $profile_row['field_length']);
|
||||
$profile_row['field_rows'] = $field_length[0];
|
||||
$profile_row['field_cols'] = $field_length[1];
|
||||
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
||||
$field_ident = $profile_row['field_ident'];
|
||||
$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('text', array_change_key_case($profile_row, CASE_UPPER));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_database_column_type()
|
||||
{
|
||||
return 'MTEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_language_options($field_data)
|
||||
{
|
||||
$options = array(
|
||||
'lang_name' => 'string',
|
||||
);
|
||||
|
||||
if ($field_data['lang_explain'])
|
||||
{
|
||||
$options['lang_explain'] = 'text';
|
||||
}
|
||||
|
||||
if (strlen($field_data['lang_default_value']))
|
||||
{
|
||||
$options['lang_default_value'] = 'text';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
|
||||
{
|
||||
if ($step == 2 && $key == 'field_length')
|
||||
{
|
||||
if ($this->request->is_set('rows'))
|
||||
{
|
||||
$field_data['rows'] = $this->request->variable('rows', 0);
|
||||
$field_data['columns'] = $this->request->variable('columns', 0);
|
||||
$current_value = $field_data['rows'] . '|' . $field_data['columns'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$row_col = explode('|', $current_value);
|
||||
$field_data['rows'] = $row_col[0];
|
||||
$field_data['columns'] = $row_col[1];
|
||||
}
|
||||
|
||||
return $current_value;
|
||||
}
|
||||
|
||||
return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function prepare_hidden_fields($step, $key, $action, &$field_data)
|
||||
{
|
||||
if ($key == 'field_length' && $this->request->is_set('rows'))
|
||||
{
|
||||
$field_data['rows'] = $this->request->variable('rows', 0);
|
||||
$field_data['columns'] = $this->request->variable('columns', 0);
|
||||
return $field_data['rows'] . '|' . $field_data['columns'];
|
||||
}
|
||||
|
||||
return parent::prepare_hidden_fields($step, $key, $action, $field_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function display_options(&$template_vars, &$field_data)
|
||||
{
|
||||
$template_vars = array_merge($template_vars, array(
|
||||
'S_TEXT' => true,
|
||||
'L_DEFAULT_VALUE_EXPLAIN' => $this->user->lang['TEXT_DEFAULT_VALUE_EXPLAIN'],
|
||||
'LANG_DEFAULT_VALUE' => $field_data['lang_default_value'],
|
||||
));
|
||||
}
|
||||
}
|
87
msd2/phpBB3/phpbb/profilefields/type/type_url.php
Normal file
87
msd2/phpBB3/phpbb/profilefields/type/type_url.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
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" max="99999" name="field_length" value="' . $field_data['field_length'] . '" />'),
|
||||
1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_minlen" value="' . $field_data['field_minlen'] . '" />'),
|
||||
2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_maxlen" 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_http') . '$#iu', $field_value))
|
||||
{
|
||||
return $this->user->lang('FIELD_INVALID_URL', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
if (!preg_match('#^' . get_preg_expression('url_http') . '$#iu', $field_value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return parent::get_profile_value($field_value, $field_data);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user