Username Colour Change MOD

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in the Customisations Database.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTICE: This forum is only for the announcement of new releases and/or updates of MODs. Any MOD support should be obtained through the Customisations Database in the support area designated for each MOD.

A direct link to support for each MOD is in the first post of the respective topic.
Locked
Extensions Robot
Extensions Robot
Extensions Robot
Posts: 28009
Joined: Sat Aug 16, 2003 7:36 am

Username Colour Change MOD

Post by Extensions Robot » Fri Jul 17, 2009 3:34 am

Modification name: Username Colour Change MOD
Author: mtrs
Modification description: Gives the option to permitted users to change own username colour. Admins can change username colours at ACP.
Modification version: 1.0.2
Tested on phpBB version: 3.0.5

Download file: Username_Colour_Change_MOD_v1-0-2.zip
File size: 49.73 KiB

Modification overview page: View

The phpBB Team is not responsible nor required to provide support for this modification. By installing this MOD, you acknowledge that the phpBB Support Team or phpBB Extensions Team may not be able to provide support.

-->Modification support<--
Last edited by Extensions Robot on Mon Mar 27, 2017 3:09 pm, edited 8 times in total.
(this is a non-active account manager for the phpBB Extension Customisations Team)

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17066
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Username Colour Change MOD

Post by DavidIQ » Fri Jul 17, 2009 3:34 am

Modification validated/released

Notes:
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Username Colour Change MOD

Post by mtrs » Fri Jul 17, 2009 3:34 am

Thank you MOD Team for validating this mod.
*******************
AutoMOD install 1.0.2 on 3.0.7-PL1 just fine. Using AutoMOD is recommended.
Also, don't forget to run database update script after file edits. See DIY section in install.xml

*******************
Demo screenshots:
ACP username colour change  and colour lock setting
ACP username colour change and colour lock setting
username-colour-acp.png (47.66 KiB) Viewed 12128 times
User Control Panel - Username Colour Change dropdown box colour options
User Control Panel - Username Colour Change dropdown box colour options
username_ucp_colours.png (16.44 KiB) Viewed 12128 times
ACP Disallow Username Colours Setting  - Euclidean distance setting
ACP Disallow Username Colours Setting - Euclidean distance setting
username_colours_dissallowed.png (17.78 KiB) Viewed 12128 times
ACP username colour change permission
ACP username colour change permission
acp-colour-permission.png (28.41 KiB) Viewed 12128 times
Last edited by mtrs on Sat Mar 06, 2010 4:35 pm, edited 1 time in total.
I abandoned all of my mods.

comkidwizzer3
Registered User
Posts: 375
Joined: Fri Jul 13, 2007 8:24 am
Location: $user->data['user_location'];
Contact:

Re: Username Colour Change MOD

Post by comkidwizzer3 » Sat Jul 18, 2009 11:27 am

Nice work, Hope you can improve this, I was thinking of if that when you type someones username it will come up with a link to their profile and will be their colour. :D
~My MODs~
Login After Register - v1.0.0 | Custom Ranks MOD - RC

~!Hasher!~

lovelysummer
Registered User
Posts: 437
Joined: Fri Mar 20, 2009 1:49 pm

Re: Username Colour Change MOD

Post by lovelysummer » Sun Jul 19, 2009 9:40 am

I like this mod. However, would you please tell me if ACP have option to turn off user to change color but remains the right for admin to change color only?

Tks

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Username Colour Change MOD

Post by mtrs » Sun Jul 19, 2009 9:57 am

comkidwizzer3 wrote:Nice work, Hope you can improve this, I was thinking of if that when you type someones username it will come up with a link to their profile and will be their colour. :D
If I understand correctly, you want to enter the name of other user for colour selection, then mod would save her/his colour as your username colour.
But, this mod does not support this, having said that, you can just use a colour picker to learn the colour code of other user, then select your colour at ucp accordingly.
lovelysummer wrote:I like this mod. However, would you please tell me if ACP have option to turn off user to change color but remains the right for admin to change color only?

Tks
There is a user permission to let users change username colour. Any user with permission can change username colour at UCP user profile. Admins can always change users' username colours at ACP user overview. But, there is also an option to prevent users taking admin and mod colours or some colour codes entered at ACP. That option only prevents selection of limited number colour codes and similar colours, then to be listed at UCP colour options. If you do not prevent any colour, just don't change those settings.

Also, there is a colour code array in function file, you can add and remove colour codes to be listed on UCP user profile colour codes dropdown box.

Open
includes/functions_user_colour.php
Find

Code: Select all

	$colour_list = array(
					"FFFFFF", "FFFFBF", "FFFF80", "FFFF40", "FFFF00",
You can add or remove colours by editing the array in function file.
I abandoned all of my mods.

lovelysummer
Registered User
Posts: 437
Joined: Fri Mar 20, 2009 1:49 pm

Re: Username Colour Change MOD

Post by lovelysummer » Sun Jul 19, 2009 7:22 pm

I have tried in my localhost , it works great and ACP can set permission to any group to change colour name.

Very nice mod.

But I have two problems in the chat body after install the mod. I have to solve them before install to my live forum.

Tks.

User avatar
Stitch625
Registered User
Posts: 683
Joined: Wed Jun 20, 2007 3:38 pm
Location: Michigan
Contact:

Re: Username Colour Change MOD

Post by Stitch625 » Mon Jul 20, 2009 1:34 am

Hi mtrs,

i am confused on how to update from 0.0.6 to the latest version. The update file says Update from 0.0.6 to 1.0.1 or 1.0.1. Not sure if that is a typo or what.

Thanks ;)

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Username Colour Change MOD

Post by mtrs » Mon Jul 20, 2009 1:45 am

Hi Stitch625,

That's a typo, it should have been,
Update from 0.0.6 to 1.0.0 or 1.0.1
and,
Update from 1.0.1 to 1.0.2
is the same as update from 0.0.6 to 1.0.2
Also need to overwrite included files to older ones
I abandoned all of my mods.

User avatar
Bobski2000
Registered User
Posts: 130
Joined: Mon Feb 16, 2009 9:40 pm
Location: UK

Re: Username Colour Change MOD

Post by Bobski2000 » Tue Jul 21, 2009 3:43 pm

Hi,

I am new to all this.

The files that i need to upload, they are slightly different to the ones i have.

So just overwite them yes?

Regards

Bobski2000

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Username Colour Change MOD

Post by mtrs » Tue Jul 21, 2009 4:04 pm

Yes, if you update, overwrite the older files. Also see the contrib folder.
I abandoned all of my mods.

User avatar
Bobski2000
Registered User
Posts: 130
Joined: Mon Feb 16, 2009 9:40 pm
Location: UK

Re: Username Colour Change MOD

Post by Bobski2000 » Tue Jul 21, 2009 4:11 pm

No, im not updating.

I have 1.0.2 version.

But was just unsure about the files to be uploaded, in the files, they are writen diffrently thats all.
But thanks for a quick reply

Bobski2000

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Username Colour Change MOD

Post by mtrs » Tue Jul 21, 2009 4:48 pm

Install it with Automod, then run install script, set permissions.
That is easier.
Bobski2000 wrote: But was just unsure about the files to be uploaded, in the files, they are writen diffrently thats all.
I wonder what is written different.
I abandoned all of my mods.

User avatar
Bobski2000
Registered User
Posts: 130
Joined: Mon Feb 16, 2009 9:40 pm
Location: UK

Re: Username Colour Change MOD

Post by Bobski2000 » Tue Jul 21, 2009 6:31 pm

Here is my functions_user_colour file. See how even the first bit is slightly different from yours.

Code: Select all

<?php
/**
*
* @package phpBB3
* @author mtrs 2009/07/14
* @version $Id$ 1.0.2 Username colour change MOD
* @copyrigh(c) 2009 mtrs
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/

if (!defined('IN_PHPBB'))
{
	exit();
}

function user_colour_update($update_user_colour, $user_id)
{
	global $db, $config;

	//We update username colours
	$sql_ary = array(
			'topic_first_poster_colour'		=> $update_user_colour,
		);
		
	$sql = 'UPDATE ' . TOPICS_TABLE . '
		SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
		WHERE topic_poster = ' . $user_id;
	$db->sql_query($sql);
	

	$sql_ary = array(
			'topic_last_poster_colour'		=> $update_user_colour,
		);
		
	$sql = 'UPDATE ' . TOPICS_TABLE . '
		SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
		WHERE topic_last_poster_id = ' . $user_id;
	$db->sql_query($sql);
	
	$sql_ary = array(
			'forum_last_poster_colour'		=> $update_user_colour,
		);	
		
	$sql = 'UPDATE ' . FORUMS_TABLE . '
		SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
		WHERE forum_last_poster_id = ' . $user_id;
	$db->sql_query($sql);
	
	if ($config['newest_user_id'] == $user_id)
	{
		set_config('newest_user_colour', $update_user_colour, true);
	}
}

function validate_colour_code($color_code)
{	
	global $config, $auth;
	//We also sanitize user entered colour code by comparing with allowed characters
	$allowed_chars = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
	$color_code = str_split(strtoupper($color_code));
	
	//Controll colour code and replace invalid chars with ''
	for ($i = 0, $j = sizeof($color_code); $i < $j; $i++)
	{
		if(!in_array($color_code[$i], $allowed_chars))
		{
			$color_code[$i] = '';
		}
	}
	$color_code = implode("", $color_code);
	if (strlen($color_code) > 6)
	{
		$color_code = substr($color_code, 0, 6);
	}

	//If you allow users enter colour codes in an input box at ucp profile page, uncomment this if() clause, thus user input codes will be controlled against admin and mod group colours	
	/*
	if ($config['uccm_euclidean_distance'] && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
	{
		global $user, $phpbb_root_path, $phpEx;
		
		$user->add_lang('mods/user_colour');
		
		//If the Euclidean distance between two colours is below delta_limit, user cannot take the similar colour
		$euclidean_distance = $config['uccm_euclidean_distance'];
		
		//Obtain $dissallowed_colours list from config table which was entered at ACP. As a reminder: the default admin_colour = "AA0000", $mod_colour = "00AA00"
		$dissallowed_colours = ($config['uccm_disallowed_colours']) ? explode(",", $config['uccm_disallowed_colours']) : array();
		
		//get_admin_mod_group_colours() function calls default admin, global mod, bot group colours from groups table, thus we don't allow them
		$dissallowed_colours = array_unique(array_merge($dissallowed_colours, get_admin_mod_group_colours()));
		
		for ($i = 0, $j = sizeof($dissallowed_colours); $i < $j; $i++)
		{
			if (similar_colour($color_code, $dissallowed_colours[$i]) < $euclidean_distance)
			{			
				meta_refresh(4, append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile'));
				$message = $user->lang['SIMILAR_COLOUR_WARNING'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile') . '">', '</a>');
				trigger_error($message, E_USER_WARNING);
			}
		}
	}
	*/
	return $color_code;
}


//HEX to RGB convert function based on http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml 
function html2rgb($color)
{
	//HEX web colour codes of usernames to be converted to RGB, thus will check colour similarity
    if ($color[0] == '#')
	{
        $color = substr($color, 1);
	}

    if (strlen($color) == 6)
	{
        list($r, $g, $b) = array($color[0].$color[1],
                                 $color[2].$color[3],
                                 $color[4].$color[5]);
    }
	elseif (strlen($color) == 3)
	{
        list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
    }
	else
	{
        return false;
	}

    $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);

    return array($r, $g, $b);
}

//http://www.compuphase.com/cmetric.htm is the reference for the formula below
//Calculate the weighted Euclidean distance in R'G'B'
// delta_euclidian = sqrt (3 x pow(deltaR', 2) + 4 x pow(deltaG', 2) + 2 x pow(deltaB', 2))
function similar_colour($color1, $color2)
{	
	//Calculte euclidian distance between HEX color1 and HEX color2
	$color1 = html2rgb($color1);
	$color2 = html2rgb($color2);	
	
	$DeltaR = ($color1[0] -  $color2[0]) * ($color1[0] -  $color2[0]);
	$DeltaG = ($color1[1] -  $color2[1]) * ($color1[1] -  $color2[1]);
	$DeltaB = ($color1[2] -  $color2[2]) * ($color1[2] -  $color2[2]);

	$delta_euclidian = sqrt((3 * $DeltaR) + (4 * $DeltaG) + (2 * $DeltaB));
		
	return round($delta_euclidian);
}


//Obtain administrator, global moderator and bots group colours from GROUPS_TABLE
function get_admin_mod_group_colours()
{
	global $db;
	
	$sql = 'SELECT group_colour, group_name
		FROM ' . GROUPS_TABLE . "
		WHERE group_type = " . GROUP_SPECIAL . "";
	$result = $db->sql_query($sql);
	
	$admin_mod_bot_colours = array();
	while ($row = $db->sql_fetchrow($result))
	{
		if ($row['group_name'] == "ADMINISTRATORS" || $row['group_name'] == "GLOBAL_MODERATORS" || $row['group_name'] == "BOTS")
		{
			$admin_mod_bot_colours[] = $row['group_colour'];
		}
	}
	$db->sql_freeresult($result);	

    return $admin_mod_bot_colours;
}

function get_colour_options()
{
	global $user, $auth, $config;

	$new_colour_list = array();

	//This is the raw colour list to be offered to users to select. Some colours may be removed if they are very similar to mod and admin colours
	//Delete any colour code from this list if you don't want users pick them 
	
	$colour_list = array(
					"FFFFFF", "FFFFBF", "FFFF80", "FFFF40", "FFFF00",
					"FFBFFF", "FFBFBF", "FFBF80", "FFBF40", "FFBF00",
					"FF80FF", "FF80BF", "FF8080", "FF8040", "FF8000",
					"FF40FF", "FF40BF", "FF4080", "FF4040", "FF4000",
					"FF00FF", "FF00BF", "FF0080", "FF0040", "FF0000",

					"BFFFFF", "BFFFBF", "BFFF80", "BFFF40", "BFFF00",
					"BFBFFF", "BFBFBF", "BFBF80", "BFBF40", "BFBF00",
					"BF80FF", "BF80BF", "BF8080", "BF8040", "BF8000",
					"BF40FF", "BF40BF", "BF4080", "BF4040", "BF4000",
					"BF00FF", "BF00BF", "BF0080", "BF0040", "BF0000",
					
					"80FFFF", "80FFBF", "80FF80", "80FF40", "80FF00",
					"80BFFF", "80BFBF", "80BF80", "80BF40", "80BF00",
					"8080FF", "8080BF", "808080", "808040", "808000",
					"8040FF", "8040BF", "804080", "804040", "804000",
					"8000FF", "8000BF", "800080", "800040", "800000",	
					
					"40FFFF", "40FFBF", "40FF80", "40FF40", "40FF00",
					"40BFFF", "40BFBF", "40BF80", "40BF40", "40BF00",
					"4080FF", "4080BF", "408080", "408040", "408000",
					"4040FF", "4040BF", "404080", "404040", "404000",
					"4000FF", "4000BF", "400080", "400040", "400000",	

					"00FFFF", "00FFBF", "00FF80", "00FF40", "00FF00",
					"00BFFF", "00BFBF", "00BF80", "00BF40", "00BF00",
					"0080FF", "0080BF", "008080", "008040", "008000",
					"0040FF", "0040BF", "004080", "004040", "004000",
					"0000FF", "0000BF", "000080", "000040", "000000",					
				);

	$user->add_lang('mods/user_colour');
	$s_colour_options = '<option value="" style="background-color: #FFFFFF">' . $user->lang['NO_COLOUR'] . '</option>';
	$s_colour_options .=	'<option value="'. $user->data['user_colour'] . '" style="background-color: #'. $user->data['user_colour'] . '" selected="selected">#'. $user->data['user_colour'] . '</option>';
	
	if ($config['uccm_euclidean_distance'] && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
	{			
		//If the Euclidean distance between two colours is below delta_limit, user cannot take the similar colour
		$euclidean_distance = $config['uccm_euclidean_distance'];
		
		//Obtain $dissallowed_colours list from config table which was entered at ACP. As a reminder: the default admin_colour = "AA0000", $mod_colour = "00AA00"
		$dissallowed_colours = ($config['uccm_disallowed_colours']) ? explode(",", $config['uccm_disallowed_colours']) : array();
		
		//get_admin_mod_group_colours() function calls default admin, global mod, bot group colours from groups table, thus we don't allow them		

		$dissallowed_colours = array_unique(array_merge($dissallowed_colours, get_admin_mod_group_colours()));		
		for ($i = 0, $j = sizeof($colour_list); $i < $j; $i++)
		{	
			for ($k = 0, $l = sizeof($dissallowed_colours); $k < $l; $k++)
			{
				if (similar_colour($colour_list[$i], $dissallowed_colours[$k]) < $euclidean_distance)
				{
					$new_colour_list[] = $colour_list[$i];
					break;
				}
			}
		}
		$tem_array = array();
		//We filter dissallowed colour codes in a new temp array
		for ($i = 0, $j = sizeof($colour_list); $i < $j; $i++)
		{		
			if (!in_array($colour_list[$i], $new_colour_list))
			{
				$tem_array[] = $colour_list[$i];
			}
		}
		$colour_list = $tem_array;		
	}
	
	for ($i = 0, $j = sizeof($colour_list); $i < $j; $i++)
	{	
		$s_colour_options .= '<option value="'.$colour_list[$i].'" style="background-color: #'.$colour_list[$i].'">#'.$colour_list[$i].'</option>';
	}
	
	return $s_colour_options;
}

?>
Last edited by Bobski2000 on Tue Jul 21, 2009 9:36 pm, edited 1 time in total.

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Username Colour Change MOD

Post by mtrs » Tue Jul 21, 2009 9:15 pm

The latest version is in MODDB, there is no change since validation.
I abandoned all of my mods.

Locked

Return to “[3.0.x] MOD Database Releases”