MyBB Community Forums

Full Version: Show welcome member user stars
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
header_welcomeblock_member
[Image: w1G2qD.jpg]
He said he wants to put them in header_welcome_member template in 1st post.

That's not so easy to achieve because you need to check if the group has stars first. If it doesn't, draw user stars. Then use for loop or something similar to draw correct number of images.

EDIT: This is the whole code for it in member.php (profile):
	$displaygroupfields = array(
		"title",
		"usertitle",
		"stars",
		"starimage",
		"image",
		"usereputationsystem"
	);
	$displaygroup = usergroup_displaygroup($memprofile['displaygroup']);

	// Get the user title for this user
	unset($usertitle);
	unset($stars);
	$starimage = '';
	if(trim($memprofile['usertitle']) != '')
	{
		// User has custom user title
		$usertitle = $memprofile['usertitle'];
	}
	elseif(trim($displaygroup['usertitle']) != '')
	{
		// User has group title
		$usertitle = $displaygroup['usertitle'];
	}
	else
	{
		// No usergroup title so get a default one
		$usertitles = $cache->read('usertitles');

		if(is_array($usertitles))
		{
			foreach($usertitles as $title)
			{
				if($memprofile['postnum'] >= $title['posts'])
				{
					$usertitle = $title['title'];
					$stars = $title['stars'];
					$starimage = $title['starimage'];

					break;
				}
			}
		}
	}
	
	if($displaygroup['stars'] || $displaygroup['usertitle'])
	{
		// Set the number of stars if display group has constant number of stars
		$stars = $displaygroup['stars'];
	}
	elseif(!$stars)
	{
		if(!is_array($usertitles))
		{
			$usertitles = $cache->read('usertitles');
		}

		// This is for cases where the user has a title, but the group has no defined number of stars (use number of stars as per default usergroups)
		if(is_array($usertitles))
		{
			foreach($usertitles as $title)
			{
				if($memprofile['postnum'] >= $title['posts'])
				{
					$stars = $title['stars'];
					$starimage = $title['starimage'];
					break;
				}
			}
		}
	}

	$groupimage = '';
	if(!empty($displaygroup['image']))
	{
		if(!empty($mybb->user['language']))
		{
			$language = $mybb->user['language'];
		}
		else
		{
			$language = $mybb->settings['bblanguage'];
		}
		$displaygroup['image'] = str_replace("{lang}", $language, $displaygroup['image']);
		$displaygroup['image'] = str_replace("{theme}", $theme['imgdir'], $displaygroup['image']);
		eval("\$groupimage = \"".$templates->get("member_profile_groupimage")."\";");
	}

	if(empty($starimage))
	{
		$starimage = $displaygroup['starimage'];
	}

	if(!empty($starimage))
	{
		// Only display stars if we have an image to use...
		$starimage = str_replace("{theme}", $theme['imgdir'], $starimage);
		$userstars = '';
		for($i = 0; $i < $stars; ++$i)
		{
			$userstars .= "<img src=\"$starimage\" border=\"0\" alt=\"*\" />";
		}
	}
Was almost correct, except that also displaygroup needs to be checked.
{$mybb->user['userstars']}

Try to use that. It should then pull the users user star. Hopefully, its a long shot and I dont have access to a computer to test it.

(2014-02-07, 03:29 PM)Destroy666 Wrote: [ -> ]He said he wants to put them in header_welcome_member template in 1st post.

That's not so easy to achieve because you need to check if the group has stars first. If it doesn't, draw user stars. Then use for loop or something similar to draw correct number of images.

But isn't the userstars a global variable? You should be able to pull the user's userstar from MyBB without any more work.
(2014-02-07, 03:31 PM)iHydra Wrote: [ -> ]{$mybb->user['userstars']}

Try to use that. It should then pull the users user star. Hopefully, its a long shot and I dont have access to a computer to test it.

negative Sad

(2014-02-07, 03:29 PM)Destroy666 Wrote: [ -> ]He said he wants to put them in header_welcome_member template in 1st post.

That's not so easy to achieve because you need to check if the group has stars first. If it doesn't, draw user stars. Then use for loop or something similar to draw correct number of images.

EDIT: This is the whole code for it in member.php (profile):
	$displaygroupfields = array(
		"title",
		"usertitle",
		"stars",
		"starimage",
		"image",
		"usereputationsystem"
	);
	$displaygroup = usergroup_displaygroup($memprofile['displaygroup']);

	// Get the user title for this user
	unset($usertitle);
	unset($stars);
	$starimage = '';
	if(trim($memprofile['usertitle']) != '')
	{
		// User has custom user title
		$usertitle = $memprofile['usertitle'];
	}
	elseif(trim($displaygroup['usertitle']) != '')
	{
		// User has group title
		$usertitle = $displaygroup['usertitle'];
	}
	else
	{
		// No usergroup title so get a default one
		$usertitles = $cache->read('usertitles');

		if(is_array($usertitles))
		{
			foreach($usertitles as $title)
			{
				if($memprofile['postnum'] >= $title['posts'])
				{
					$usertitle = $title['title'];
					$stars = $title['stars'];
					$starimage = $title['starimage'];

					break;
				}
			}
		}
	}
	
	if($displaygroup['stars'] || $displaygroup['usertitle'])
	{
		// Set the number of stars if display group has constant number of stars
		$stars = $displaygroup['stars'];
	}
	elseif(!$stars)
	{
		if(!is_array($usertitles))
		{
			$usertitles = $cache->read('usertitles');
		}

		// This is for cases where the user has a title, but the group has no defined number of stars (use number of stars as per default usergroups)
		if(is_array($usertitles))
		{
			foreach($usertitles as $title)
			{
				if($memprofile['postnum'] >= $title['posts'])
				{
					$stars = $title['stars'];
					$starimage = $title['starimage'];
					break;
				}
			}
		}
	}

	$groupimage = '';
	if(!empty($displaygroup['image']))
	{
		if(!empty($mybb->user['language']))
		{
			$language = $mybb->user['language'];
		}
		else
		{
			$language = $mybb->settings['bblanguage'];
		}
		$displaygroup['image'] = str_replace("{lang}", $language, $displaygroup['image']);
		$displaygroup['image'] = str_replace("{theme}", $theme['imgdir'], $displaygroup['image']);
		eval("\$groupimage = \"".$templates->get("member_profile_groupimage")."\";");
	}

	if(empty($starimage))
	{
		$starimage = $displaygroup['starimage'];
	}

	if(!empty($starimage))
	{
		// Only display stars if we have an image to use...
		$starimage = str_replace("{theme}", $theme['imgdir'], $starimage);
		$userstars = '';
		for($i = 0; $i < $stars; ++$i)
		{
			$userstars .= "<img src=\"$starimage\" border=\"0\" alt=\"*\" />";
		}
	}
Was almost correct, except that also displaygroup needs to be checked.
yes I've tried but did not work global.php.
(2014-02-07, 03:31 PM)iHydra Wrote: [ -> ]{$mybb->user['userstars']}

But isn't the userstars a global variable? You should be able to pull the user's userstar from MyBB without any more work.

Never heard of {$mybb->user['userstars']}, tested it and nothing shows up for me.. It's also not on a list of a script that shows all $mybb variables.

(2014-02-07, 03:34 PM)Raphaelx Wrote: [ -> ]yes I've tried but did not work global.php.

Well, you can't put the same code (needs to be modified for current user) and you need to put it to correct place. Probably inc/class_core.php would be better suited as it a class which controls $mybb.
Pages: 1 2