$forumperms = $DB_site->query("
  SELECT forumid,canview
  FROM forumpermission
  WHERE usergroupid=$bbuserinfo[usergroupid]
");

while ( $forumperm = $DB_site->fetch_array( $forumperms ) )
{
  $ipermcache["$forumperm[forumid]"] = $forumperm;
}
$DB_site->free_result( $forumperms );
unset( $forumperm );
$getforums = $DB_site->query("
  SELECT forumid,parentid,displayorder
  FROM forum
  WHERE displayorder<>0 AND active=1
  ORDER BY parentid,displayorder
");

while ( $getforum = $DB_site->fetch_array( $getforums ) )
{
  $iforumcache["$getforum[parentid]"]["$getforum[displayorder]"]["$getforum[forumid]"] = $getforum;
  if ( !isset( $ipermcache["$getforum[forumid]"]['canview'] ) )
  {
    $iforumperms[] = $getforum['forumid'];
  }
}

$DB_site->free_result( $getforums );
unset( $getforum );
if ( !empty( $iforumperms ) )
{
  $iforumperms = 'AND thread.forumid IN( ' . implode( ',' , $iforumperms ) . ' )';
}


///// vB3 Similar Threads v.2 | By Velocd \\\\\ (thnx to Teck for above code ^_^)

$limit = 4; //Amount of threads to show

///----\\\

$count=0;
$sthreads=$DB_site->query("SELECT

thread.threadid,thread.lastposter,thread.title,thread.postusername,thread.replycount,thread.

lastpost,thread.postuserid,
			thread.dateline,forum.title AS

ftitle,forum.forumid,forum.parentlist
			FROM thread
			LEFT JOIN forum ON (thread.forumid=forum.forumid) 
			WHERE thread.threadid<>$thread[threadid] $iforumperms
			AND MATCH(thread.title) AGAINST ('".addslashes($thread[title])."')
			AND thread.open<>10
			AND thread.visible=1
			ORDER BY dateline DESC
			LIMIT $limit");

while ($sthread = $DB_site->fetch_array($sthreads)) {

		$sthread[date] = vbdate($dateformat, $sthread[lastpost]);
		$sthread[time] = vbdate($timeformat, $sthread[lastpost]);

		$count++;

		eval("\$similarthreadbits .=\"".gettemplate("showthread_similarthreadbits")."\";");

}

if (!empty($count))
{
   eval("\$similarthreads =\"".gettemplate("showthread_similarthreads")."\";");
}