MyBB Community Forums

Full Version: Requests and a Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Ok I haven't tested this code, so give this a try and tell me the results:

In your phpMyAdmin, navigate to your mybb_themes table (change mybb_ to your forum's table prefix if it's different). Add a column called 'usergroups' (without the quotation marks) and make it VARCHAR 100.

Open inc/functions.php. Replace the existing themeselect function with:
function themeselect($name, $selected="", $tid=0, $depth="", $usergroup="")
{
	global $db, $themeselect, $tcache, $lang, $tgroupcache;
	if(!$tid)
	{
		$themeselect = "<select name=\"$name\">";
		$themeselect .= "<option value=\"0\">".$lang->use_default."</option>\n";
		$themeselect .= "<option value=\"0\">-----------</option>\n";
	}
	if(!is_array($tcache))
	{
		$query = $db->query("SELECT name,pid,tid FROM ".TABLE_PREFIX."themes ORDER BY pid, name");
		while($theme = $db->fetch_array($query))
		{
			$tcache[$theme['pid']][$theme['tid']] = $theme;
		}
	}
	if(!is_array($tgroupcache))
	{
		$query = $db->query("SELECT tid,usergroups FROM ".TABLE_PREFIX."themes");
		while($row = $db->fetch_array($query))
		{
			$tgroupcache[$row['tid']] = $row['usergroups'];
		}
	}
	if(is_array($tcache[$tid]))
	{
		if(!empty($usergroup) && !is_array($usergroup))
		{
			$in_groups = array($usergroup);
		}
		elseif(!empty($usergroup) && is_array($usergroup))
		{
			$in_groups = $usergroup;
		}
		else
		{
			$in_groups = false;
		}
		foreach($tcache[$tid] as $theme)
		{
			$allowed = explode(',', $tgroupcache[$theme['tid']]);
			if(empty($tgroupcache[$theme['tid']]) || !$in_groups || in_array($in_groups, $allowed))
			{
				$sel = "";
				if($theme['tid'] == $selected)
				{
					$sel = "selected=\"selected\"";
				}
				if($theme['pid'] != 0)
				{
					$themeselect .= "<option value=\"".$theme['tid']."\" $sel>".$depth.$theme['name']."</option>";
					$depthit = $depth."--";
				}
				if(is_array($tcache[$theme['tid']]))
				{
					themeselect($name, $selected, $theme['tid'], $depthit, $usergroup);
				}
			}
		}
	}
	if(!$tid)
	{
		$themeselect .= "</select>";
	}
	return $themeselect;
}

Open usergroup.php.
Find:
	$stylelist = themeselect("style", $mybb->user['style']);
Replace with:
	$ugarray = explode(',', $mybb->user['additionalgroups']);
	$ugarray[] = $mybb->user['usergroup'];
	$stylelist = themeselect("style", $mybb->user['style'],0,"",$ugarray);

Open admin/themes.php.
Find:
	$themearray = array(
		"name" => addslashes($mybb->input['name']),
Add after:
		"usergroups" => addslashes($mybb->input['usergroups']),
Find next (should be several lines below):
	$themearray = array(
		"name" => addslashes($mybb->input['name']),
Add after:
		"usergroups" => addslashes($mybb->input['usergroups']),
Find:
	makeinputcode($lang->theme_name, "name");
Add after:
	makeinputcode("Allowed Usergroups (separate by comma, or leave blank for all groups)", "usergroups");
Find:
	makeinputcode($lang->theme_name, "name", $theme['name']);
Add after:
	makeinputcode("Allowed Usergroups (separate by comma, or leave blank for all groups)", "usergroups", $theme['usergroups']);

Again, I haven't tested this code, so tell me what errors you get and we'll troubleshoot it.
I couldn't find the line of codes in usergroups.php, but found it in usercp.php, so I edited usercp.php instead.

Now, I tried adding a theme and left the Allowed Usergroups field empty, and it works. Another theme I filled it with Administrators, but the theme doesn't appear in my User CP.

Also, umm...how do I go about making a theme that was previously set to restricted view to public? I don't seem see any switch in Edit/ Delete Theme...

Should have mentioned this before, it's the usergroup ID, so you would put in 4 for the Administrators group only. and 4,3 for supermods and administrators.

Quote:Find:
PHP Code:

makeinputcode($lang->theme_name, "name", $theme['name']);


Add after:
PHP Code:

makeinputcode("Allowed Usergroups (separate by comma, or leave blank for all groups)", "usergroups", $theme['usergroups']);

That part should add a setting in the theme edit page...
Quote:That part should add a setting in the theme edit page...
Oops...forgot to add that portion. My bad, sorry.

The usergoup thing, added the number (4), but the selected style is still not showing up in my User CP. It shows up tho, when I leave the Allowed Usergroups field blank.
Pages: 1 2