MyBB Community Forums

Full Version: Warnings on Profile
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to make a plugin that displays all warnings a user has received on their profile. It is only visible to the user and anyone who can issue warnings. Some profiles it works fine on, but others it doesn't. I can't find a common reason for some to not work so I am going to post my code in hopes someone can figure it out.

<?php

/* Info stuff is here */

function viewwarnings_install()
{
	global $cache, $mybb;
}

function viewwarnings_activate()
{
}

function viewwarnings_deactivate()
{
}

function viewwarnings_uninstall()
{
}

$plugins->add_hook("member_profile_start", "viewwarnings_view");

function viewwarnings_view()
{
	global $db, $mybb, $lang, $templates, $warnings;
	$memberid = intval($mybb->input['uid']);
	$lang->load("warnings");
	if($mybb->user['uid']!=$memberid && $mybb->usergroup['canwarnusers']!=1)
	{
		return;
	}
	$user = get_user(intval($mybb->input['uid']));
	if(!$user['uid'])
	{
		error($lang->error_invalid_user);
	}
	$group_permissions = user_permissions($user['uid']);

	$lang->nav_profile = $lang->sprintf($lang->nav_profile, $user['username']);
	add_breadcrumb($lang->nav_profile, get_profile_link($user['uid']));
	add_breadcrumb($lang->nav_warning_log);

	if(!$mybb->settings['postsperpage'])
	{
		$mybb->settings['postperpage'] = 20;
	}
		
	// Figure out if we need to display multiple pages.
	$perpage = $mybb->settings['postsperpage'];
	$page = intval($mybb->input['page']);

	$query = $db->simple_select("warnings", "COUNT(wid) AS warning_count", "uid='{$user['uid']}'");
	$warning_count = $db->fetch_field($query, "warning_count");

	$pages = ceil($warning_count/$perpage);

	if($page > $pages || $page <= 0)
	{
		$page = 1;
	}
	if($page)
	{
		$start = ($page-1) * $perpage;
	}
	else
	{
		$start = 0;
		$page = 1;
	}

	$multipage = multipage($warning_count, $perpage, $page, "warnings.php?uid={$user['uid']}");

	$warning_level = round($user['warningpoints']/$mybb->settings['maxwarningpoints']*100);
	if($warning_level > 100)
	{
		$warning_level = 100;
	}
	
	if($user['warningpoints'] > $mybb->settings['maxwarningpoints'])
	{
		$user['warningpoints'] = $mybb->settings['maxwarningpoints'];
	}
	
	if($warning_level > 0)
	{
		$lang->current_warning_level = $lang->sprintf($lang->current_warning_level, $warning_level, $user['warningpoints'], $mybb->settings['maxwarningpoints']);
	}
	else
	{
		$lang->current_warning_level = "";
	}

	// Fetch the actual warnings
	$query = $db->query("
		SELECT w.*, t.title AS type_title, u.username, p.subject AS post_subject
		FROM ".TABLE_PREFIX."warnings w
		LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (t.tid=w.tid)
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=w.issuedby)
		LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=w.pid)
		WHERE w.uid='{$user['uid']}'
		ORDER BY w.expired ASC, w.dateline DESC
		LIMIT {$start}, {$perpage}
	");
	$first = true;
	while($warning = $db->fetch_array($query))
	{
		if($warning['expired'] != $last_expired || $first)
		{
			if($warning['expired'] == 0)
			{
				eval("\$warnings .= \"".$templates->get("warnings_active_header")."\";");
			}
			else
			{
				eval("\$warnings .= \"".$templates->get("warnings_expired_header")."\";");
			}
		}
		$last_expired = $warning['expired'];
		$first = false;

		$post_link = "";
		if($warning['post_subject'])
		{
			$warning['post_subject'] = $parser->parse_badwords($warning['post_subject']);
			$warning['post_subject'] = htmlspecialchars_uni($warning['post_subject']);
			$post_link = "<br /><small>{$lang->warning_for_post} <a href=\"".get_post_link($warning['pid'])."#pid{$warning['pid']}\">{$warning['post_subject']}</a></small>";
		}
		$issuedby = build_profile_link($warning['username'], $warning['issuedby']);
		$date_issued = my_date($mybb->settings['dateformat'], $warning['dateline']).", ".my_date($mybb->settings['timeformat'], $warning['dateline']);
		if($warning['type_title'])
		{
			$warning_type = $warning['type_title'];
		}
		else
		{
			$warning_type = $warning['title'];
		}
		$warning_type = htmlspecialchars_uni($warning_type);
		if($warning['points'] > 0)
		{
			$warning['points'] = "+{$warning['points']}";
		}
		$points = $lang->sprintf($lang->warning_points, $warning['points']);
		if($warning['expired'] != 1)
		{
			if($warning['expires'] == 0)
			{
				$expires = $lang->never;
			}
			else
			{
				$expires = my_date($mybb->settings['dateformat'], $warning['expires']).", ".my_date($mybb->settings['timeformat'], $warning['expires']);
			}
		}
		else
		{
			if($warning['daterevoked'])
			{
				$expires = $lang->warning_revoked;
			}
			else if($warning['expires'])
			{
				$expires = $lang->already_expired;
			}
		}
		$alt_bg = alt_trow();
		eval("\$warnings .= \"".$templates->get("warnings_warning")."\";");
	}

	if(!$warnings)
	{
		eval("\$warnings = \"".$templates->get("warnings_no_warnings")."\";");
	}
	eval("\$warnings = \"".$templates->get("warnings")."\";");
	return $warnings;
}

?>

Due to the forum it isn't working on being large, I disabled the plugin. I pretty much copied the code from warnings.php exactly. Any ideas?
Instead using;
$mybb->input['uid']
Use;
$memprofile['uid']
And add $memprofile as global object.

Next, change;
member_profile_start
to;
member_profile_end
Since $memprofile is not evaluated on that "start" hook.
I did those changes but I'm still getting a 500 Server error on certain profiles.
working profile
non-working profile

edit: disabling until I get a response.