<?php

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

//推荐主题
$whereadd="";
if($m_day){
	$dayago=time()-$m_day*86400;
	$whereadd.=" and t.dateline>'$dayago'";
}
if($m_typeids){
	$whereadd.=" and t.typeid in ($m_typeids)";
}
if($m_sortids){
	$whereadd.=" and t.sortid in ($m_sortids)";
}
if($m_onlypic){
	$whereadd.=" and t.attachment=2 ";
}
$begin=($_G['page']-1)*$m_num;
$needupdate=0;
$manylist=array();
$cachefile="data/cache/forumthreaddy.cache";
if($m_cachetime){
		if(($_G['timestamp']-@filemtime($cachefile))<$m_cachetime){
			$c=@file_get_contents($cachefile);
			$manylist=unserialize($c);
			$allnum=intval($manylist['allnum']);
			unset($manylist['allnum']);
		}else{
			$needupdate=1;
		}
}else{
	$needupdate=1;
}
if($needupdate){
require_once libfile('function/post');
$rs=DB::query("
SELECT t.*,p.message,p.pid,f.name
FROM ".DB::table("forum_thread")." t 
LEFT JOIN ".DB::table("forum_post")." p on p.tid=t.tid and p.first=1
LEFT JOIN ".DB::table("forum_forum")." f on f.fid=t.fid
WHERE t.`fid` in ($m_fids) and t.displayorder>=0 $whereadd  
ORDER BY t.`$m_order` DESC
LIMIT $begin , $m_num");
while ($rw=DB::fetch($rs)) {
	$rw['message']=messagecutstr($rw['message'],$m_messagelength,'');
	$rw['message']=dhtmlspecialchars($rw['message']);
	$manylist[]=$rw;
}
$allnum=DB::result_first("select count(*) from ".DB::table("forum_thread")." t where t.fid in ($m_fids)  and t.displayorder>=0 $whereadd");
$manylist['allnum']=$allnum;
	$c=serialize($manylist);
	@file_put_contents($cachefile,$c);
unset($manylist['allnum']);
}
$pagenav=multi($allnum,$m_num,$_G['page'],"forum.php?mod=pic");


//楼主新帖
$newauthorthreadlist=array();
$rs=DB::query("SELECT tid,subject 
FROM ".DB::table("forum_thread")."
WHERE `authorid` ='{$_G['forum_thread']['authorid']}'
and tid!={$_G['tid']} and displayorder>=0
order by dateline desc
LIMIT 0 ,3");
while ($rw=DB::fetch($rs)){
	$newauthorthreadlist[]=$rw;
}

?>