Warrior Protection
User avatar
EU Hydraxian Waterlords
donator Posts: 1325
Likes: 2548
Orc
Warrior

This is a small collection of core code changes to phpBB that I have either created myself or hired a developer to create. These are not extensions, they are changes to the core PHP/Language files on the most part. Hopefully you will find these useful for your board!

Always remember to keep a log of which core files you have edited and the lines of code you edited in each core file. Upgrading phpBB involved overwriting all core files, so you'll need to re-append all of your core work.

What I'm sharing below is basically my core changes file, with Find/Add before/Add after/Replace with instructions. I am using phpBB 3.2.5 and PHP 7.1 for the following modifications:

How to show current user's rank image in navbar or globally
How to automatically set user's style according to profile field value chosen during registration
How to automatically set user's avatar according to profile field value chosen during registration
How to skip the terms and conditions and confirmation pages during registration
How to remove numbers next to module titles in private message UCP

Show current user's rank image in navbar (or any other global location)

This mod will allow the current user to see their own rank image in any global template location. On barrens.chat it is in the main navbar but you could place it anywhere you liked.

In /includes/functions.php

Find, around line 4389:

Code: Select all

'CURRENT_USER_AVATAR'			=> phpbb_get_user_avatar($user->data),

Add after:

Code: Select all

'CURRENT_USER_RANK_TITLE'	=> $user_rank['title'],
	'CURRENT_USER_RANK_IMG'		=> $user_rank['img'],

Find, around line 4522:

Code: Select all

'T_UPLOAD'				=> $config['upload_path'],

Add after:

Code: Select all

'RANK_IMG'				=> '',

Automatically set user's style according to profile field value chosen during registration

If your users can fill in any profile fields on the registration page, this mod will read those fields and automatically set the user's board style depending on what they entered after successful registration.

In the following example the user can select one of eight radio buttons (but it could be a drop down or any other <input>) as their profile field choice. Each different choice corresponds with a different Style ID.

In /includes/functions_user.php

Find, around line 253:

Code: Select all

// Now fill the sql array with not required variables

Add before:

Code: Select all

$profile_field_id = 'faction';

	$profile_option_to_style = [
		0 => 2,
		'horde.png|25|25' => 2,
		'alliance.png|25|25' => 3,
		'Tauren.png|25|25' => 5,
		'Orc.png|25|25'    => 2,
		'Troll.png|25|25'  => 2,
		'Undead.png|25|25' => 7,
		'Human.png|25|25'  => 3,
		'Dwarf.png|25|25'  => 4,
		'Gnome.png|25|25'  => 4,
		'Night_Elf.png|25|25' => 6,
	];

	if (isset($cp_data['pf_' . $profile_field_id]) && isset($profile_option_to_style[$cp_data['pf_' . $profile_field_id]]))
		
	{
		$additional_vars['user_style'] = $profile_option_to_style[$cp_data['pf_' . $profile_field_id]];
	}

  • 'faction' is changed to whatever the name="" HTML attribute of all your inputs are.
  • 'horde.png|25|25' is the value="" HTML attribute of a specific input, in this case it is a .PNG image with 25x25px dimensions.
  • '=> 2,' is mapping that specific value input to a style ID (the number 2). To find your style IDs go into phpMyAdmin and there is a column next to each style's name specifying it's style ID.
  • '0 => 2,' is the fallback. In case the user didn't select anything, it will use the default style.

So for example, if a user registers having chosen the 'Tauren.png|25|25' input, the board will automatically set their board style to the style with the ID '5', which is the 'Mulgore' skin on my website.

Automatically set user's avatar according to profile field value chosen during registration

Like the previous mod (go read it - as a lot of it is relevant to this mod), this will read the user's profile field choice during registration and set their avatar accordingly upon successful registration.

Each profile field is linked to two different avatars (a male and a female version) - of which one of the two is randomly selected when the user registers. The configuration is the same as the previous mod, using name="" and value="" attributes to specify which profile field to link to each avatar.

In /includes/functions_user.php

Find, around line 253:

Code: Select all

// Now fill the sql array with not required variables

Add after:

Code: Select all

	$profile_field_id = 'faction';

		$avatar_category = 'WoW Classic/Races and Classes';

		$profile_option_to_avatars = [
			'0'                => 'default.png',
			'alliance.png|25|25'   => 'human_%1$s.png',
			'horde.png|25|25' => 'orc_%1$s.png',
			'Tauren.png|25|25' => 'tauren_%1$s.png',
			'Orc.png|25|25'    => 'orc_%1$s.png',
			'Troll.png|25|25'  => 'troll_%1$s.png',
			'Undead.png|25|25' => 'undead_%1$s.png',
			'Human.png|25|25'  => 'human_%1$s.png',
			'Dwarf.png|25|25'  => 'dwarf_%1$s.png',
			'Gnome.png|25|25'  => 'gnome_%1$s.png',
			'Night_Elf.png|25|25' => 'nelf_%1$s.png',
		];

		if (isset($cp_data['pf_' . $profile_field_id]) && isset($profile_option_to_avatars[$cp_data['pf_' . $profile_field_id]]))
			{
				global $request, $template, $user;

				$gender = rand(0, 1) ? 'male' : 'female';
				$avatar_file = sprintf($profile_option_to_avatars[$cp_data['pf_' . $profile_field_id]], $gender);

				$request->overwrite('avatar_local_cat', $avatar_category);
				$request->overwrite('avatar_local_file', $avatar_file);

				/* @var $phpbb_avatar_manager \phpbb\avatar\manager */
				$avatar_driver_name = 'avatar.driver.local';
				$phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
				$driver = $phpbb_avatar_manager->get_driver($avatar_driver_name);

				$error = [];
				$result = $driver->process_form($request, $template, $user, [], $error);

				if ($result && !$error)
				{
					$additional_vars = array_merge($additional_vars, [
						'user_avatar'            => $result['avatar'],
						'user_avatar_type'        => $avatar_driver_name,
						'user_avatar_width'        => $result['avatar_width'],
						'user_avatar_height'    => $result['avatar_height'],
					]);
				}
			}	
			

Configuration is the same as for the previous mod.

Skip the terms and conditions and confirmation pages during registration


Noone reads it anyway let's be honest - this mod bypasses the T&C page and takes the user straight to the registration form. In the page footer of course there is a link to the T&Cs so that they are still available for viewing.

After registering, the second block of code also skips the 'you have successfully registered, return to the forum index' confirmation page and instead takes them straight to the index page again. Bear in mind this will hide any activation instructions you may have for your users so use wisely!

In /includes/ucp/ucp_register.php

Find, around line 43:

Code: Select all

$agreed			= $request->variable('agreed', false);

Replace with:

Code: Select all

$agreed			= $request->variable('agreed', true);

Find, around line 511:

Code: Select all

$message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
					trigger_error($message);

Replace with:

Code: Select all

redirect(append_sid("{$phpbb_root_path}index.$phpEx"));

Remove numbers next to module titles in private message UCP


This removes the numbers in brackets like (3) next to the Outbox and Sent folder navigation links in the UCP. I've left alone the number for inbox as this is actually useful unlike the others.

In /includes/functions_privmsgs.php

Find, around line 182:

Code: Select all

db->sql_freeresult($result);

	$folder[PRIVMSGS_OUTBOX] = array(
		'folder_name'		=> $user->lang['PM_OUTBOX'],
		'num_messages'		=> $num_messages[PRIVMSGS_OUTBOX],
		'unread_messages'	=> $num_unread[PRIVMSGS_OUTBOX]
	);

	$folder[PRIVMSGS_SENTBOX] = array(
		'folder_name'		=> $user->lang['PM_SENTBOX'],
		'num_messages'		=> $num_messages[PRIVMSGS_SENTBOX],
		'unread_messages'	=> $num_unread[PRIVMSGS_SENTBOX]
	);

Replace with:

Code: Select all

$db->sql_freeresult($result);

	$folder[PRIVMSGS_OUTBOX] = array(
		'folder_name'		=> $user->lang['PM_OUTBOX']
	);

	$folder[PRIVMSGS_SENTBOX] = array(
		'folder_name'		=> $user->lang['PM_SENTBOX']
	);
Any questions or issues just ask here and I'll help you out.
Teeb

   neofrag Kaladin