MyBB Community Forums

Full Version: [Plugin] Nickname Styles
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Plugin Name: Nickname Styles
Plugin Author: Edson Ordaz
Plugin Website: http://www.mybb-es.com
Plugin Version: 1.0
Plugin Mybb Compatibility: 1.6x
Plugin Description: allows users to edit the style of his nickname.


Admin panel

To change the tab to go to the users and the last module where it says nickname style and enter there.

It will show the table with styles created and two options are to edit and delete.

Creating new style
To create a new way to click on the tab and enter the new style name, style, posts, reputation, time online, and order groups.

Name: Enter the name of style.
Style: Style nickname, you must enter {username} as this will replace the user's name
Posts: Enter the number of messages you need to use this style.
Points: Enter the number of reputation you need to use this style.
Uptime: Enter the number of days / months you need to have the online user to use this style.
Groups: Select the user groups to be able to use this style of nickname.
Order: Enter the order in which they show with the other styles.

This is the configuration with the styles


User Control Panel

Go to control panel user / edit profile and even below this nickname styles and displays a select input to select the style you want (only nickname styles show your user group can see if you comply with the time online, messages and reputation).
Below is a fieldset with the style of your current nickname and down a link to a page, if you click there will open a popup with all styles of his nickname but show styles and his nickname to see which you like best and you choose.

Always on the list will come the default nickname is the style of the group.

*Important:

For operation of the plugin to edit the functions.php file that is inside root / inc if your file is modified and will have to modify it again to add the following.

Open your functions.php file with some preferred editor notepad + + and look for the following

function format_name($username, $usergroup, $displaygroup="")
{
	global $groupscache, $cache;

	if(!is_array($groupscache))
	{
		$groupscache = $cache->read("usergroups");
	}

	if($displaygroup != 0)
	{
		$usergroup = $displaygroup;
	}

	$ugroup = $groupscache[$usergroup];
	$format = $ugroup['namestyle'];
	$userin = substr_count($format, "{username}");

	if($userin == 0)
	{
		$format = "{username}";
	}

	$format = stripslashes($format);

	return str_replace("{username}", $username, $format);
}


and replacing this

function format_name($username, $usergroup, $displaygroup="")
{
	global $groupscache, $cache, $db;

	if(!is_array($groupscache))
	{
		$groupscache = $cache->read("usergroups");
	}

	if($displaygroup != 0)
	{
		$usergroup = $displaygroup;
	}

	$ugroup = $groupscache[$usergroup];
	$format = $ugroup['namestyle'];
	$userin = substr_count($format, "{username}");

	if($userin == 0)
	{
		$format = "{username}";
	}

	$format = stripslashes($format);
	
	if($db->table_exists("nickstyles_nicks"))
	{
		global $db;
		$query = $db->simple_select('users', 'nickstyle', "username='{$username}' AND usergroup='{$usergroup}'");
		$user = $db->fetch_array($query);
		if(!empty($user['nickstyle']))
		{
			$query = $db->simple_select('nickstyles_nicks', 'style', 'nid='.$user['nickstyle']);
			$style = $db->fetch_array($query);
			$format = $style['style'];
			$format = stripslashes($format);
			return str_replace("{username}", $username, $format);
		}
		else
		{
			return str_replace("{username}", $username, $format);
		}
	}

	return str_replace("{username}", $username, $format);
}

and if it is modified to put the functions.php that is inside the attachment.


Screenshots
[Image: 25549-1333826336-1.thumb.png] [Image: 25549-1333826374-2.thumb.png] [Image: 25549-1333826449-3.thumb.png] [Image: 25549-1333826467-4.thumb.png] [Image: 25549-1333826495-5.thumb.png] [Image: 25549-1333826517-6.thumb.png] [Image: 25549-1333826537-7.thumb.png]


Downloads Mods MyBB
http://mods.mybb.com/view/nickname-styles
english version????
1. Why not use profile fields?
2. If you used profile fields you can get rid of the extra queries in the function by using user global.
3. You can also create a cache of the nick styles and use that to avoid the queries too.

Every time format_name runs you now run 2 queries. On a showthread this is potential for a lot of load.

Cache the nickstyles_nicks table. Make your plugin more efficient.