2008-01-22, 05:19 PM
Here's the function:
// Jump to the last post.
if($mybb->input['action'] == "lastpost")
{
if(strstr($thread['closed'], "moved|"))
{
$query = $db->query("
SELECT p.pid
FROM ".TABLE_PREFIX."posts p, ".TABLE_PREFIX."threads t
WHERE t.fid='".$thread['fid']."' AND t.closed NOT LIKE 'moved|%' AND p.tid=t.tid
ORDER BY p.dateline DESC
LIMIT 0, 1
");
$pid = $db->fetch_field($query, "pid");
}
else
{
$options = array(
'order_by' => 'dateline',
'order_dir' => 'desc',
'limit_start' => 0,
'limit' => 1
);
$query = $db->simple_select(TABLE_PREFIX.'posts', 'pid', "tid={$tid}", $options);
$pid = $db->fetch_field($query, "pid");
}
header("Location:showthread.php?tid={$tid}&pid={$pid}#pid{$pid}");
exit;
}
// Jump to the last post.
if($mybb->input['action'] == "lastpost")
{
if(strstr($thread['closed'], "moved|"))
{
$query = $db->query("
SELECT p.pid
FROM ".TABLE_PREFIX."posts p, ".TABLE_PREFIX."threads t
WHERE t.fid='".$thread['fid']."' AND t.closed NOT LIKE 'moved|%' AND p.tid=t.tid
ORDER BY p.dateline DESC
LIMIT 0, 1
");
$pid = $db->fetch_field($query, "pid");
}
else
{
$options = array(
'order_by' => 'dateline',
'order_dir' => 'desc',
'limit_start' => 0,
'limit' => 1
);
$query = $db->simple_select(TABLE_PREFIX.'posts', 'pid', "tid={$tid}", $options);
$pid = $db->fetch_field($query, "pid");
}
header("Location:showthread.php?tid={$tid}&pid={$pid}#pid{$pid}");
exit;
}