phpBB

Code Changes

File: includes/acp/acp_profile.php

  Unmodified   Added   Modified   Removed
Line 25Line 25

var $edit_lang_id;
var $lang_defs;


var $edit_lang_id;
var $lang_defs;

 

/**
* @var \phpbb\di\service_collection
*/

	protected $type_collection;

function main($id, $mode)
{

	protected $type_collection;

function main($id, $mode)
{

		global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
global $request, $phpbb_container;

		global $config, $db, $user, $template;
global $phpbb_root_path, $phpEx;
global $request, $phpbb_container, $phpbb_log, $phpbb_dispatcher;





 
		if (!function_exists('generate_smilies'))
{

		include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);

		include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);

 
		}

if (!function_exists('user_get_id_name'))
{

		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

 
		}


$user->add_lang(array('ucp', 'acp/profile'));
$this->tpl_name = 'acp_profile';
$this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS';

$field_id = $request->variable('field_id', 0);


$user->add_lang(array('ucp', 'acp/profile'));
$this->tpl_name = 'acp_profile';
$this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS';

$field_id = $request->variable('field_id', 0);

		$action = (isset($_POST['create'])) ? 'create' : request_var('action', '');

		$action = (isset($_POST['create'])) ? 'create' : $request->variable('action', '');


$error = array();


$error = array();

		$s_hidden_fields = '';




$form_key = 'acp_profile';
add_form_key($form_key);


if (!$field_id && in_array($action, array('delete','activate', 'deactivate', 'move_up', 'move_down', 'edit')))
{
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
}



if (!$field_id && in_array($action, array('delete','activate', 'deactivate', 'move_up', 'move_down', 'edit')))
{
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
}


 
		/* @var $cp \phpbb\profilefields\manager */

		$cp = $phpbb_container->get('profilefields.manager');
$this->type_collection = $phpbb_container->get('profilefields.type_collection');


		$cp = $phpbb_container->get('profilefields.manager');
$this->type_collection = $phpbb_container->get('profilefields.type_collection');


Line 112Line 126
					$db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
$db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");


					$db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
$db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");


 
					/* @var $db_tools \phpbb\db\tools\tools_interface */

					$db_tools = $phpbb_container->get('dbal.tools');
$db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_' . $field_ident);


					$db_tools = $phpbb_container->get('dbal.tools');
$db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_' . $field_ident);


Line 137Line 152

$db->sql_transaction('commit');



$db->sql_transaction('commit');


					add_log('admin', 'LOG_PROFILE_FIELD_REMOVED', $field_ident);

					$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_REMOVED', false, array($field_ident));

					trigger_error($user->lang['REMOVED_PROFILE_FIELD'] . adm_back_link($this->u_action));
}
else

					trigger_error($user->lang['REMOVED_PROFILE_FIELD'] . adm_back_link($this->u_action));
}
else

Line 153Line 168
			break;

case 'activate':

			break;

case 'activate':

 

if (!check_link_hash($request->variable('hash', ''), 'acp_profile'))
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}


$sql = 'SELECT lang_id
FROM ' . LANG_TABLE . "


$sql = 'SELECT lang_id
FROM ' . LANG_TABLE . "

Line 178Line 198
				$field_ident = (string) $db->sql_fetchfield('field_ident');
$db->sql_freeresult($result);


				$field_ident = (string) $db->sql_fetchfield('field_ident');
$db->sql_freeresult($result);


				add_log('admin', 'LOG_PROFILE_FIELD_ACTIVATE', $field_ident);

				$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_ACTIVATE', false, array($field_ident));


if ($request->is_ajax())
{


if ($request->is_ajax())
{

Line 193Line 213
			break;

case 'deactivate':

			break;

case 'deactivate':

 

if (!check_link_hash($request->variable('hash', ''), 'acp_profile'))
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}


$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
SET field_active = 0


$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
SET field_active = 0

Line 214Line 239
					));
}


					));
}


				add_log('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', $field_ident);

				$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_DEACTIVATE', false, array($field_ident));


trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action));



trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action));


Line 222Line 247

case 'move_up':
case 'move_down':


case 'move_up':
case 'move_down':

 

if (!check_link_hash($request->variable('hash', ''), 'acp_profile'))
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}


$sql = 'SELECT field_order
FROM ' . PROFILE_FIELDS_TABLE . "


$sql = 'SELECT field_order
FROM ' . PROFILE_FIELDS_TABLE . "

Line 255Line 285
			case 'create':
case 'edit':


			case 'create':
case 'edit':


				$step = request_var('step', 1);

				$step = $request->variable('step', 1);


$submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
$save = (isset($_REQUEST['save'])) ? true : false;


$submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
$save = (isset($_REQUEST['save'])) ? true : false;

Line 319Line 349
					// We are adding a new field, define basic params
$lang_options = $field_row = array();


					// We are adding a new field, define basic params
$lang_options = $field_row = array();


					$field_type = request_var('field_type', '');

					$field_type = $request->variable('field_type', '');


if (!isset($this->type_collection[$field_type]))
{


if (!isset($this->type_collection[$field_type]))
{

Line 328Line 358

$profile_field = $this->type_collection[$field_type];
$field_row = array_merge($profile_field->get_default_option_values(), array(


$profile_field = $this->type_collection[$field_type];
$field_row = array_merge($profile_field->get_default_option_values(), array(

						'field_ident'		=> str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))),

						'field_ident'		=> str_replace(' ', '_', utf8_clean_string($request->variable('field_ident', '', true))),

						'field_required'	=> 0,
'field_show_novalue'=> 0,
'field_hide' => 0,

						'field_required'	=> 0,
'field_show_novalue'=> 0,
'field_hide' => 0,

Line 341Line 371
						'field_is_contact'	=> 0,
'field_contact_desc'=> '',
'field_contact_url' => '',

						'field_is_contact'	=> 0,
'field_contact_desc'=> '',
'field_contact_url' => '',

						'lang_name'			=> utf8_normalize_nfc(request_var('field_ident', '', true)),

						'lang_name'			=> $request->variable('field_ident', '', true),

						'lang_explain'		=> '',
'lang_default_value'=> '')
);

						'lang_explain'		=> '',
'lang_default_value'=> '')
);

Line 368Line 398
					'field_hide',
'field_is_contact',
);

					'field_hide',
'field_is_contact',
);

 

/**
* Event to add initialization for new profile field table fields
*
* @event core.acp_profile_create_edit_init
* @var string action create|edit
* @var int step Configuration step (1|2|3)
* @var bool submit Form has been submitted
* @var bool save Configuration should be saved
* @var string field_type Type of the field we are dealing with
* @var array field_row Array of data about the field
* @var array exclude Array of excluded fields by step
* @var array visibility_ary Array of fields that are visibility related
* @since 3.1.6-RC1
*/
$vars = array(
'action',
'step',
'submit',
'save',
'field_type',
'field_row',
'exclude',
'visibility_ary',
);
extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_init', compact($vars)));


$options = $profile_field->prepare_options_form($exclude, $visibility_ary);



$options = $profile_field->prepare_options_form($exclude, $visibility_ary);


				$cp->vars['field_ident']		= ($action == 'create' && $step == 1) ? utf8_clean_string(request_var('field_ident', $field_row['field_ident'], true)) : request_var('field_ident', $field_row['field_ident']);

				$cp->vars['field_ident']		= ($action == 'create' && $step == 1) ? utf8_clean_string($request->variable('field_ident', $field_row['field_ident'], true)) : $request->variable('field_ident', $field_row['field_ident']);

				$cp->vars['lang_name']			= $request->variable('lang_name', $field_row['lang_name'], true);
$cp->vars['lang_explain'] = $request->variable('lang_explain', $field_row['lang_explain'], true);
$cp->vars['lang_default_value'] = $request->variable('lang_default_value', $field_row['lang_default_value'], true);

				$cp->vars['lang_name']			= $request->variable('lang_name', $field_row['lang_name'], true);
$cp->vars['lang_explain'] = $request->variable('lang_explain', $field_row['lang_explain'], true);
$cp->vars['lang_default_value'] = $request->variable('lang_default_value', $field_row['lang_default_value'], true);

Line 410Line 466
				// step 2
foreach ($exclude[2] as $key)
{

				// step 2
foreach ($exclude[2] as $key)
{

					$var = utf8_normalize_nfc(request_var($key, $field_row[$key], true));

					$var = $request->variable($key, $field_row[$key], true);


$field_data = $cp->vars;
$var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 2);


$field_data = $cp->vars;
$var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 2);

Line 456Line 512

foreach ($exclude[3] as $key)
{


foreach ($exclude[3] as $key)
{

					$cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => ''), true));

					$cp->vars[$key] = $request->variable($key, array(0 => ''), true);


if (!$cp->vars[$key] && $action == 'edit')
{


if (!$cp->vars[$key] && $action == 'edit')
{

						$cp->vars[$key] = $$key;

						$cp->vars[$key] = ${$key};

					}

$field_data = $cp->vars;

					}

$field_data = $cp->vars;

Line 510Line 566
						}
}
}

						}
}
}


$step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step);

 

if (sizeof($error))
{


if (sizeof($error))
{

					$step--;

 
					$submit = false;

					$submit = false;

 
				}
else
{
$step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step);

				}

// Build up the specific hidden fields

				}

// Build up the specific hidden fields

Line 535Line 592
						$var = $profile_field->prepare_hidden_fields($step, $key, $action, $field_data);
if ($var !== null)
{

						$var = $profile_field->prepare_hidden_fields($step, $key, $action, $field_data);
if ($var !== null)
{

							$_new_key_ary[$key] = $profile_field->prepare_hidden_fields($step, $key, $action, $field_data);

							$_new_key_ary[$key] = $var;

						}
}
$cp->vars = $field_data;

						}
}
$cp->vars = $field_data;

Line 545Line 602

if (!sizeof($error))
{


if (!sizeof($error))
{

					if ($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save))

					if (($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save)) || ($action == 'edit' && $save))

					{

					{

						$this->save_profile_field($cp, $field_type, $action);
}
else if ($action == 'edit' && $save)

						if (!check_form_key($form_key))



					{

					{

 
							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}


						$this->save_profile_field($cp, $field_type, $action);
}
}

						$this->save_profile_field($cp, $field_type, $action);
}
}

Line 643Line 701

break;
}


break;
}

 

$field_data = $cp->vars;
/**
* Event to add template variables for new profile field table fields
*
* @event core.acp_profile_create_edit_after
* @var string action create|edit
* @var int step Configuration step (1|2|3)
* @var bool submit Form has been submitted
* @var bool save Configuration should be saved
* @var string field_type Type of the field we are dealing with
* @var array field_data Array of data about the field
* @var array s_hidden_fields Array of hidden fields in case this needs modification
* @var array options Array of options specific to this step
* @since 3.1.6-RC1
*/
$vars = array(
'action',
'step',
'submit',
'save',
'field_type',
'field_data',
's_hidden_fields',
'options',
);
extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_after', compact($vars)));


$template->assign_vars(array(
'S_HIDDEN_FIELDS' => $s_hidden_fields)


$template->assign_vars(array(
'S_HIDDEN_FIELDS' => $s_hidden_fields)

Line 672Line 757
				$s_one_need_edit = true;
}


				$s_one_need_edit = true;
}


 
			if (!isset($this->type_collection[$row['field_type']]))
{
continue;
}

			$profile_field = $this->type_collection[$row['field_type']];
$template->assign_block_vars('fields', array(
'FIELD_IDENT' => $row['field_ident'],
'FIELD_TYPE' => $profile_field->get_name(),

'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang],

			$profile_field = $this->type_collection[$row['field_type']];
$template->assign_block_vars('fields', array(
'FIELD_IDENT' => $row['field_ident'],
'FIELD_TYPE' => $profile_field->get_name(),

'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang],

				'U_ACTIVATE_DEACTIVATE'		=> $this->u_action . "&action=$active_value&field_id=$id",

				'U_ACTIVATE_DEACTIVATE'		=> $this->u_action . "&action=$active_value&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'),

				'U_EDIT'					=> $this->u_action . "&action=edit&field_id=$id",
'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",

				'U_EDIT'					=> $this->u_action . "&action=edit&field_id=$id",
'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",

				'U_MOVE_UP'					=> $this->u_action . "&action=move_up&field_id=$id",
'U_MOVE_DOWN' => $this->u_action . "&action=move_down&field_id=$id",

				'U_MOVE_UP'					=> $this->u_action . "&action=move_up&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'),
'U_MOVE_DOWN' => $this->u_action . "&action=move_down&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'),


'S_NEED_EDIT' => $s_need_edit)
);


'S_NEED_EDIT' => $s_need_edit)
);

Line 713Line 802
	*/
function build_language_options(&$cp, $field_type, $action = 'create')
{

	*/
function build_language_options(&$cp, $field_type, $action = 'create')
{

		global $user, $config, $db, $phpbb_container;

		global $user, $config, $db, $request;


$default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];



$default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];


Line 754Line 843
			$lang_options[$lang_id]['lang_iso'] = $lang_iso;
foreach ($options as $field => $field_type)
{

			$lang_options[$lang_id]['lang_iso'] = $lang_iso;
foreach ($options as $field => $field_type)
{

				$value = ($action == 'create') ? utf8_normalize_nfc(request_var('l_' . $field, array(0 => ''), true)) : $cp->vars['l_' . $field];

				$value = ($action == 'create') ? $request->variable('l_' . $field, array(0 => ''), true) : $cp->vars['l_' . $field];

				if ($field == 'lang_options')
{
$var = (!isset($cp->vars['l_lang_options'][$lang_id]) || !is_array($cp->vars['l_lang_options'][$lang_id])) ? $cp->vars['lang_options'] : $cp->vars['l_lang_options'][$lang_id];

				if ($field == 'lang_options')
{
$var = (!isset($cp->vars['l_lang_options'][$lang_id]) || !is_array($cp->vars['l_lang_options'][$lang_id])) ? $cp->vars['lang_options'] : $cp->vars['l_lang_options'][$lang_id];

Line 810Line 899
	*/
function save_profile_field(&$cp, $field_type, $action = 'create')
{

	*/
function save_profile_field(&$cp, $field_type, $action = 'create')
{

		global $db, $config, $user, $phpbb_container;

		global $db, $config, $user, $phpbb_container, $phpbb_log, $request, $phpbb_dispatcher;





		$field_id = request_var('field_id', 0);

		$field_id = $request->variable('field_id', 0);


// Collect all information, if something is going wrong, abort the operation
$profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array();


// Collect all information, if something is going wrong, abort the operation
$profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array();

Line 851Line 940
			'field_contact_desc'	=> $cp->vars['field_contact_desc'],
'field_contact_url' => $cp->vars['field_contact_url'],
);

			'field_contact_desc'	=> $cp->vars['field_contact_desc'],
'field_contact_url' => $cp->vars['field_contact_url'],
);

 

$field_data = $cp->vars;
/**
* Event to modify profile field configuration data before saving to database
*
* @event core.acp_profile_create_edit_save_before
* @var string action create|edit
* @var string field_type Type of the field we are dealing with
* @var array field_data Array of data about the field
* @var array profile_fields Array of fields to be sent to the database
* @since 3.1.6-RC1
*/
$vars = array(
'action',
'field_type',
'field_data',
'profile_fields',
);
extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_save_before', compact($vars)));


if ($action == 'create')
{


if ($action == 'create')
{

Line 880Line 988
		if ($action == 'create')
{
$field_ident = 'pf_' . $field_ident;

		if ($action == 'create')
{
$field_ident = 'pf_' . $field_ident;



			/* @var $db_tools \phpbb\db\tools\tools_interface */

			$db_tools = $phpbb_container->get('dbal.tools');
$db_tools->sql_column_add(PROFILE_FIELDS_DATA_TABLE, $field_ident, array($profile_field->get_database_column_type(), null));
}

			$db_tools = $phpbb_container->get('dbal.tools');
$db_tools->sql_column_add(PROFILE_FIELDS_DATA_TABLE, $field_ident, array($profile_field->get_database_column_type(), null));
}

Line 1079Line 1187

if ($action == 'edit')
{


if ($action == 'edit')
{

			add_log('admin', 'LOG_PROFILE_FIELD_EDIT', $cp->vars['field_ident'] . ':' . $cp->vars['lang_name']);

			$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_EDIT', false, array($cp->vars['field_ident'] . ':' . $cp->vars['lang_name']));

			trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action));
}
else
{

			trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action));
}
else
{

			add_log('admin', 'LOG_PROFILE_FIELD_CREATE', substr($field_ident, 3) . ':' . $cp->vars['lang_name']);

			$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_CREATE', false, array(substr($field_ident, 3) . ':' . $cp->vars['lang_name']));

			trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action));
}
}

			trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action));
}
}