MyBB Community Forums

Full Version: Problems with evaluating template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For some reason it's not really evaluating this template:

<tr>
<td class="trow1"><a href="{$settings['bburl']}/showgroup.php?gid={$socialgroup['sgid']}">{$socialgroup['name']}</a></td>
<td class="trow1">{$socialgroup['numdisc']}</td>
</tr>

Plugin code:

function socialgroups_member_profile()
{
	global $db, $memprofile, $templates, $lang;
	$userid = intval($_REQUEST['uid']);
	$query = $db->query("SELECT groupsin FROM ".TABLE_PREFIX."users WHERE uid=$userid");
	$meminfo = $db->fetch_array($query);
	$sgids = $meminfo['groupsin'];
	$socialgroupquery = $db->query("SELECT * FROM ".TABLE_PREFIX."socialgroups WHERE sgid IN ($sgids) ORDER BY name ASC");
	while ($socialgroup = $db->fetch_array($socialgroupquery))
	{
		eval("\$socialgroups .= \"".$templates->get("profile_socialgroup_list")."\";");
	}
}

Hook used: member_profile_start

I'm also unsure of getting it to cache additional templates on pages so it doesn't have to use a query.
I managed to get it to cache the template. I am now using this code for the function

function socialgroups_member_profile()
{
	global $db, $memprofile, $templates, $lang;
	$userid = intval($_REQUEST['uid']);
	$query = $db->query("SELECT groupsin FROM ".TABLE_PREFIX."users WHERE uid=$userid");
	$meminfo = $db->fetch_array($query);
	$sgids = $meminfo['groupsin'];
	$socialgroupquery = $db->query("SELECT * FROM ".TABLE_PREFIX."socialgroups WHERE sgid IN ($sgids) ORDER BY name ASC");
	while ($socialgroup = $db->fetch_array($socialgroupquery))
	{
		eval("\$socialgrouplist .= \"".$templates->get("profile_social_group_list")."\";");
	}
	eval("\$socialgroups = \"".$templates->get("profile_social_group_page")."\";");
	return $socialgroups;
}

I have {$socialgroups} in my member_profile template, but it doesn't output the html for the templates.
Try

function socialgroups_member_profile()
{
    global $db, $memprofile, $templates, $lang, $socialgroups;
    $userid = intval($_REQUEST['uid']);
    $query = $db->query("SELECT groupsin FROM ".TABLE_PREFIX."users WHERE uid=$userid");
    $meminfo = $db->fetch_array($query);
    $sgids = $meminfo['groupsin'];
    $socialgroupquery = $db->query("SELECT * FROM ".TABLE_PREFIX."socialgroups WHERE sgid IN ($sgids) ORDER BY name ASC");
    while ($socialgroup = $db->fetch_array($socialgroupquery))
    {
        eval("\$socialgrouplist .= \"".$templates->get("profile_social_group_list")."\";");
    }
    eval("\$socialgroups = \"".$templates->get("profile_social_group_page")."\";");
}
Worked, thanks. Smile
Also, for security, you may want this:

function socialgroups_member_profile()
{
    global $mybb,$db, $memprofile, $templates, $lang, $socialgroups;
    $userid = intval($mybb->input['uid']);
    $query = $db->query("SELECT groupsin FROM ".TABLE_PREFIX."users WHERE uid='{$userid}'");
    $meminfo = $db->fetch_array($query);
    $sgids = $meminfo['groupsin'];
    $socialgroupquery = $db->query("SELECT * FROM ".TABLE_PREFIX."socialgroups WHERE sgid IN ($sgids) ORDER BY name ASC");
    while ($socialgroup = $db->fetch_array($socialgroupquery))
    {
        eval("\$socialgrouplist .= \"".$templates->get("profile_social_group_list")."\";");
    }
    eval("\$socialgroups = \"".$templates->get("profile_social_group_page")."\";");
} 
What's the difference that using the input method of the mybb class?
It does a little bit of sanitization. Also it keeps input variables uniform across MyBB. You can see it here: http://www.mybb.com/sourcedocs/nav.html?...ource.html