MyBB Community Forums

Full Version: Viewing User\'s Threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A few things:

1) "Viewing User's Threads" when viewing "all", should be "Viewing User's Recent Threads" depending on the next one.

2) How long does it class a thread as recent?? It displayed all my posts. If that is what its supposed to to, should it just be search.php?action=finduser&uid=1

3) On the view all. I get 8 pages of posts when I only have 1 and a bit, so 6 are empty.
In answer to your points...

1. When you are viewing all threads, you're not just viewing recent ones, so the title "Viewing User's Recent Threads" would no longer be appropriate.

2. The threads you see as recent are simply the last threads that user posted. By default, you see the ten most recent threads on your profile pages.

3. It took a while to figure out some bugs with the multipages. I'll have a look at the code again tomorrow to see if I see anymore errors.
Actually, for number three I may already have found the problem.

If you've already installed the mod, look at the bottom of member.php for this block of code...

// Get user's recent threads
elseif($action == "viewthreads")
{
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid='$uid'");
	$user = $db->fetch_array($query);
	if(!$user)
	{
		error("The member you specified is either invalid or doesn't exist.", $settings['bbname']);
	}
	$comma = "";
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."forumpermissions WHERE gid='$mybb[usergroup]'");
	while($permissions = $db->fetch_array($query))
	{
		if($permissions['canview'] != "yes")
		{
			$unviewableforums .= $comma.$permissions['fid'];
			$comma = ",";
		}
	}
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads WHERE uid='$uid' AND fid NOT IN ('$unviewableforums')");
	$threadcount = $db->num_rows($query);
	if($threadcount < 1)
	{
		error("This member has not yet posted any threads.", $settings['bbname']);
	}
	$limit = $settings['threadsperpage'];
	if(!$page)
	{
		$page = 1;
	}
	$startat = ($page - 1) * $limit;                                                                                                                                                                                                                 
	$query = $db->query("SELECT t.*, f.name, i.path, u.username, u.uid AS 'lastposteruid' FROM ".TABLE_PREFIX."threads t LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid) LEFT JOIN ".TABLE_PREFIX."icons i ON (i.iid=t.icon) LEFT JOIN ".TABLE_PREFIX."users u ON (u.username=t.lastposter) WHERE t.uid='$uid' AND t.fid NOT IN ('$unviewableforums') ORDER BY dateline DESC LIMIT $startat, $limit");
	while($thread = $db->fetch_array($query))
	{
		if($bgcolor == "trow2")
		{
			$bgcolor = "trow1";
		}
		else
		{
			$bgcolor = "trow2";
		}
		if(!empty($thread['path']))
		{
			$icon = "<img src=\\"".$thread['path']."\\">";
		}
		$thread['lastposttime'] = mydate($settings['dateformat'], $thread['dateline'])." ".mydate($settings['timeformat'], $thread['dateline']);
		eval("\\$threads .= \\"".$templates->get("member_userthreads_thread")."\\";");
		unset($icon);
	}
	$multipage = multipage($threadcount, 3, $page, "member.php?action=viewthreads&uid=$uid");
	eval("\\$userthreads = \\"".$templates->get("member_userthreads")."\\";");
	outputpage($userthreads);
}
// End user's srecent threads

...and replace it with this...

// Get user's recent threads
elseif($action == "viewthreads")
{
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid='$uid'");
	$user = $db->fetch_array($query);
	if(!$user)
	{
		error("The member you specified is either invalid or doesn't exist.", $settings['bbname']);
	}
	$comma = "";
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."forumpermissions WHERE gid='$mybb[usergroup]'");
	while($permissions = $db->fetch_array($query))
	{
		if($permissions['canview'] != "yes")
		{
			$unviewableforums .= $comma.$permissions['fid'];
			$comma = ",";
		}
	}
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads WHERE uid='$uid' AND fid NOT IN ('$unviewableforums')");
	$threadcount = $db->num_rows($query);
	if($threadcount < 1)
	{
		error("This member has not yet posted any threads.", $settings['bbname']);
	}
	$limit = $settings['threadsperpage'];
	if(!$page)
	{
		$page = 1;
	}
	$startat = ($page - 1) * $limit;                                                                                                                                                                                                                 
	$query = $db->query("SELECT t.*, f.name, i.path, u.username, u.uid AS 'lastposteruid' FROM ".TABLE_PREFIX."threads t LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid) LEFT JOIN ".TABLE_PREFIX."icons i ON (i.iid=t.icon) LEFT JOIN ".TABLE_PREFIX."users u ON (u.username=t.lastposter) WHERE t.uid='$uid' AND t.fid NOT IN ('$unviewableforums') ORDER BY dateline DESC LIMIT $startat, $limit");
	while($thread = $db->fetch_array($query))
	{
		if($bgcolor == "trow2")
		{
			$bgcolor = "trow1";
		}
		else
		{
			$bgcolor = "trow2";
		}
		if(!empty($thread['path']))
		{
			$icon = "<img src=\\"".$thread['path']."\\">";
		}
		$thread['lastposttime'] = mydate($settings['dateformat'], $thread['dateline'])." ".mydate($settings['timeformat'], $thread['dateline']);
		eval("\\$threads .= \\"".$templates->get("member_userthreads_thread")."\\";");
		unset($icon);
	}
	$multipage = multipage($threadcount, $limit, $page, "member.php?action=viewthreads&uid=$uid");
	eval("\\$userthreads = \\"".$templates->get("member_userthreads")."\\";");
	outputpage($userthreads);
}
// End user's srecent threads

The previous block included a couple of little mods I made to the code for testing purposes which should have been removed.

As always, the download package has now been updated to incorportate these changes.
2. hmm, maybe you dont know what I mean:

I set the maximum of thread to show on profile to 5, not 10. So at the bottom of the table, there is the link [ View All ]. Clicking it leads me to a page of thread Ive posted. The way I see it, search.php?action=finduser&uid=1 and member.php?action=viewthreads&uid=1 do exactly the same thing, just different style. Can you just use the default search.php?action=finduser&uid=1 ??

Thanks for number 3.
No, member.php?action=viewthreads and search.php?action=finduser are actually different.

The search page will return a list of all the threads and posts by that user. The member page only returns a list of threads posted by the user.
ah, I see. Thanks for clearing that up.
Fix for users seeying posts where they don't have permission:

Find: (twice)
	$comma = "";
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."forumpermissions WHERE gid='$mybb[usergroup]'");
	while($permissions = $db->fetch_array($query))
	{
		if($permissions['canview'] != "yes")
		{
			$unviewableforums .= $comma.$permissions['fid'];
			$comma = ",";
		}
	}

Change to: (twice)
	// Get forum permissions
	$unviewableforums = getunviewableforums();
	if($unviewableforums) {
		$fidnot = " AND fid NOT IN ($unviewableforums)";
	}
	
	// Get forum permissions2
	$unviewableforums2 = getunviewableforums();
	if($unviewableforums2) {
		$fidnot2 = " AND t.fid NOT IN ($unviewableforums2)";
	}

Find: (twice)
AND t.fid NOT IN ('$unviewableforums')

change to: (twice)
$fidnot2

Find: (twice)
AND fid NOT IN ('$unviewableforums')

change to: (twice)
$fidnot

Have fun :-)